package com.suray.wcs.web.system.controller;

import com.alibaba.fastjson.JSON;
import com.suray.basic.wcs.path.core.Node;
import com.suray.basic.wcs.plc.core.Plc;
import com.suray.basic.wcs.plc.entity.PlcDeviceDB;
import com.suray.basic.wcs.plc.pojo.oper.*;
import com.suray.basic.wcs.plc.pojo.oper.single.*;
import com.suray.basic.wcs.plc.service.IPlcDeviceDBService;
import com.suray.basic.wcs.plc.oper.PlcOper;
import com.suray.basic.wcs.plc.service.impl.PlcDeviceDBServiceImpl;
import com.suray.basic.wcs.plc.oper.impl.PlcOperImpl;
import com.suray.basic.wcs.plc.pojo.*;
import com.suray.basic.wcs.utils.WcsFuncUtil;
import com.suray.commin.annotation.Log;
import com.suray.commin.core.controller.ResponseData;
import com.suray.commin.enmus.BusinessType;
import com.suray.wcs.service.init.SystemInit;
import com.suray.wcs.service.plc.thread.FoldingManualAction;
import com.suray.wcs.service.plc.util.FoldingManualType;
import com.suray.wcs.service.pojo.*;
import com.suray.wcs.service.util.WcsUtil;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RestController
@RequestMapping("/plcDeviceManualOperation")
public class PlcDeviceManualOperation {
    @Autowired
    private PlcDeviceDBServiceImpl plcDeviceDBServiceImpl;

    private Logger log = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private IPlcDeviceDBService plcdevicedbService;

    /*************************************** 系统 ****************************/
    @PreAuthorize("@ss.hasPermi('plcDeviceDB:control')")
    @Log(title = "plc设备手动操作", method = "系统手动操作", businessType = BusinessType.UPDATE)
    @PostMapping("/plcSystemDevice")
    @ResponseBody
    @ApiOperation("系统手动操作")
    public ResponseData plcSystemDevice(@RequestBody String deviceName) {
        SystemOper systemOper = (SystemOper) Plc.deviceBaseNameMap.get(deviceName);
        if (StringUtils.isEmpty(deviceName) || systemOper == null) {
            return ResponseData.error("系统中无名称为" + deviceName + "的设备，请确认后重试");
        }
        HandleSystem dm = new HandleSystem();
        //设备编号
        dm.setDeviceNo(Integer.toString(systemOper.getDeviceNum()));
        //读取完成信号
        dm.setReadCompletionSignal(systemOper.getReadCompletionSignal() ? "完成" : "无效");
        //数据合格
        dm.setDataQualified(systemOper.getDataQualified() == 0 ? "无效" : (systemOper.getDataQualified() == 1 ? "合格" : "不合格"));
        //工位编号
        dm.setStationNo(Integer.toString(systemOper.getStationNo()));
        //运转方向
        dm.setRunDirection(systemOper.getRunDirection() == 0 ? "停止" : (systemOper.getRunDirection() == 1 ? "入库" : "出库"));
        //托盘号
        dm.setPalletNo(Integer.toString(systemOper.getPalletNo()));
        //起始工位编号
        dm.setStartStationNo(Integer.toString(systemOper.getStartStationNo()));
        //目的工位编号
        dm.setEndStationNo(Integer.toString(systemOper.getEndStationNo()));
        //自动门编号
        dm.setAutoDoor(Integer.toString(systemOper.getAutoDoor()));
        //开启自动门
        dm.setOpenAutoDoor(systemOper.getOpenAutoDoor() == 0 ? "无效" : (systemOper.getOpenAutoDoor() == 1 ? "开启" : "关闭"));
        dm.setSystemModel(systemOper.isSystemModel() ? "手动" : "非手动");
        dm.setAutoDistance(systemOper.isAutoDistance() ? "远程" : "非远程");
        dm.setAutoLocality(systemOper.isAutoLocality() ? "本地" : "非本地");
        dm.setSystemStop(systemOper.isSystemStop() ? "急停中" : "未急停");
        dm.setConveyCrashStop1(systemOper.isConveyCrashStop1() ? "急停中" : "未急停");
        dm.setConveyCrashStop2(systemOper.isConveyCrashStop2() ? "急停中" : "未急停");
        dm.setConveyCrashStop3(systemOper.isConveyCrashStop3() ? "急停中" : "未急停");
        dm.setCheckBit("" + systemOper.getCheckBit());
        return ResponseData.success(dm);
    }

    /*************************************** 称重 ****************************/

    /**
     * 获取称重数据
     *
     * @param deviceName 设备名称
     * @return
     */
    @PreAuthorize("@ss.hasPermi('plcDeviceDB:control')")
    @ApiOperation("获取称重数据")
    @PostMapping("/plcWeightDeviceR")
    @ResponseBody
    public ResponseData plcWeightDeviceR(@RequestBody String deviceName) {
        HandleWeight hw = plcdevicedbService.plcWeightDeviceR(deviceName);
        if (hw == null) {
            return ResponseData.error("系统中无名称为" + deviceName + "的设备，请确认后重试");
        }
        return ResponseData.success(hw);
    }

    /**
     * 设置称重读取完成
     *
     * @param deviceName
     * @return
     */
    @PreAuthorize("@ss.hasPermi('plcDeviceManualOperation:plcWeightDeviceReadFinish')")
    @Log(title = "plc设备手动操作", method = "设置称重读取完成", businessType = BusinessType.UPDATE)
    @ApiOperation("设置称重读取完成")
    @PostMapping("/plcWeightDeviceReadFinish")
    @ResponseBody
    public ResponseData plcWeightDeviceReadFinish(@RequestBody String deviceName) {
        WeightingEquipmentOper weightOper = (WeightingEquipmentOper) Plc.deviceBaseNameMap.get(deviceName);
        if (StringUtils.isEmpty(deviceName) || weightOper == null) {
            return ResponseData.error("系统中无名称为" + deviceName + "的设备，请确认后重试");
        }
        PlcOper plcOper = PlcOperImpl.getPlcOper(weightOper.getPlc());
        try {
            plcOper.readComplete(weightOper.getDeviceNo(), true);
        } catch (IOException e) {
            return ResponseData.error("通讯异常,设置称重读取完成失败");
        }
        return ResponseData.success("设置称重读取完成,成功");
    }

    /**
     * 设置称重是否合格
     *
     * @param result
     * @return
     */
    @PreAuthorize("@ss.hasPermi('plcDeviceManualOperation:plcWeightDeviceW')")
    @Log(title = "plc设备手动操作", method = "设置称重是否合格", businessType = BusinessType.UPDATE)
    @ApiOperation("设置称重是否合格")
    @PostMapping("/plcWeightDeviceW")
    @ResponseBody
    public ResponseData plcWeightDeviceW(@RequestBody WriteResult result) {
        String deviceName = result.getDeviceName();
        Integer weightResult = result.getResult();
        WeightingEquipmentOper weightOper = (WeightingEquipmentOper) Plc.deviceBaseNameMap.get(deviceName);
        if (StringUtils.isEmpty(deviceName) || weightOper == null) {
            return ResponseData.error("系统中无名称为" + deviceName + "的设备，请确认后重试");
        }
        PlcOper plcOper = PlcOperImpl.getPlcOper(weightOper.getPlc());
        switch (weightResult) {
            case 0:
                try {
                    plcOper.dataEligible(weightOper.getDeviceNo(), true);
                } catch (IOException e) {
                    return ResponseData.error("通讯异常,设置称重合格失败!");
                }
                return ResponseData.success("设置称重合格成功!");
            case 1:
                try {
                    plcOper.dataEligible(weightOper.getDeviceNo(), false);
                } catch (IOException e) {
                    return ResponseData.error("通讯异常,设置称重不合格失败");
                }
                return ResponseData.success("设置称重不合格成功");
            default:
                return ResponseData.error("不合法的参数!");
        }
    }


    /******************************************外形检测***********************************/
    /**
     * 外形检测
     *
     * @param deviceName
     * @return
     */
    @PreAuthorize("@ss.hasPermi('plcDeviceDB:control')")
    @ApiOperation("外形检测")
    @PostMapping("/plcShapeDeviceR")
    @ResponseBody
    public ResponseData plcShapeDeviceR(@RequestBody String deviceName) {
        HandleShape hs = plcdevicedbService.plcShapeDeviceR(deviceName);
        if (hs == null) {
            return ResponseData.error("系统中无名称为" + deviceName + "的设备，请确认后重试");
        }
        return ResponseData.success(hs);
    }

    /**
     * 设置外形检测读取完成
     *
     * @param deviceName
     * @return
     */
    @PreAuthorize("@ss.hasPermi('plcDeviceManualOperation:plcShapeDeviceWR')")
    @Log(title = "plc设备手动操作", method = "设置外形检测读取完成", businessType = BusinessType.UPDATE)
    @ApiOperation("设置外形检测读取完成")
    @PostMapping("/plcShapeDeviceWR")
    @ResponseBody
    public ResponseData plcShapeDeviceWR(@RequestBody String deviceName) {
        HandleShape hs = plcdevicedbService.plcShapeDeviceR(deviceName);
        if (hs == null) {
            return ResponseData.error("系统中无名称为" + deviceName + "的设备，请确认后重试");
        }
        ShapeDetectorOper oper = (ShapeDetectorOper) Plc.deviceBaseNameMap.get(deviceName);
        if (oper == null) {
            return ResponseData.error(deviceName + ":不在线！");
        }
        PlcOper plcOper = PlcOperImpl.getPlcOper(oper.getPlc());
        try {
            plcOper.readComplete(oper.getDeviceNo(), true);
        } catch (IOException e) {
            return ResponseData.error("通讯异常,外形检测读取完成设置失败!");
        }
        return ResponseData.success("外形检测读取完成设置成功");
    }


    /**
     * 设置外形检测合格信号
     *
     * @param result
     * @return
     */
    @PreAuthorize("@ss.hasPermi('plcDeviceManualOperation:plcShapDeviceW')")
    @Log(title = "plc设备手动操作", method = "设置外形检测合格信号", businessType = BusinessType.UPDATE)
    @ApiOperation("设置外形检测合格信号")
    @PostMapping("/plcShapDeviceW")
    @ResponseBody
    public ResponseData plcShapDeviceW(@RequestBody WriteResult result) {
        String deviceName = result.getDeviceName();
        Integer shapResult = result.getResult();
        ShapeDetectorOper shapeDetectorOper = (ShapeDetectorOper) Plc.deviceBaseNameMap.get(deviceName);
        if (StringUtils.isEmpty(deviceName) || shapeDetectorOper == null) {
            return ResponseData.error("系统中无名称为" + deviceName + "的设备，请确认后重试");
        }
        PlcOper plcOper = PlcOperImpl.getPlcOper(shapeDetectorOper.getPlc());
        switch (shapResult) {
            case 0:
                try {
                    plcOper.dataEligible(shapeDetectorOper.getDeviceNo(), true);
                } catch (IOException e) {
                    return ResponseData.error("通讯异常,设置外形检测合格失败!");
                }
                return ResponseData.success("设置外形检测合格成功!");
            case 1:
                try {
                    plcOper.dataEligible(shapeDetectorOper.getDeviceNo(), false);
                } catch (IOException e) {
                    return ResponseData.error("通讯异常,设置外形检测不合格失败!");
                }
                return ResponseData.success("设置外形检测不合格成功!");
            default:
                return ResponseData.error("不合法的参数!");
        }
    }

    /*************************************** 工位  ****************************/
    /**
     * 工位信息获取
     *
     * @param deviceName
     * @return
     */
    @PreAuthorize("@ss.hasPermi('plcDeviceDB:control')")
    @PostMapping("/plcChainStautsDeviceR")
    @ApiOperation("手动控制工位")
    @ResponseBody
    public ResponseData plcChainStatusDeviceR(@RequestBody String deviceName) {
        HandleChainStatus hcs = plcdevicedbService.plcChainStationDeviceR(deviceName);
        if (hcs == null) {
            return ResponseData.error("系统中无名称为" + deviceName + "的设备，请确认后重试");
        }
        return ResponseData.success("", hcs);
    }


    @PreAuthorize("@ss.hasPermi('plcDeviceManualOperation:plcChainStautsDeviceWE')")
    @Log(title = "plc设备手动操作", method = "工位任务完成编号清理", businessType = BusinessType.UPDATE)
    @ApiOperation("工位任务完成编号清理")
    @PostMapping("/plcChainStautsDeviceWE")
    @ResponseBody
    public ResponseData cleanStationTaskNo(@RequestBody String deviceName) {
        log.info("清除设备" + deviceName + "的任务编号");
        StationOper stationOper = (StationOper) Plc.deviceBaseNameMap.get(deviceName);
        if (stationOper == null) {
            return ResponseData.error(deviceName + ":不在线！");
        }
        PlcOper plcOper = PlcOperImpl.getPlcOper(stationOper.getPlc());
        try {
            log.info("开始发送读取完成信号");
            plcOper.readComplete(stationOper.getDeviceNo(), true);
            log.info("发送读取完成信号结束");
        } catch (IOException e) {
            return ResponseData.error("网络异常!任务完成编号清理失败!");
        }
        return ResponseData.success("任务完成编号清理完成!");
    }

    @PreAuthorize("@ss.hasPermi('plcDeviceDB:control')")
    @ApiOperation("拆码盘机预留")
    @PostMapping("/plcDishDeviceR")
    @ResponseBody
    public ResponseData plcDishDeviceR(@RequestBody String deviceName) {
        HandleDishTemp hdt = plcdevicedbService.plcDishDeviceR(deviceName);
        if (hdt == null) {
            return ResponseData.error("系统中无此设备，请确认后重试");
        }
        return ResponseData.success(hdt);
    }

    @PreAuthorize("@ss.hasPermi('plcDeviceManualOperation:plcDishDeviceW')")
    @Log(title = "plc设备手动操作", method = "拆码盘机任务完成编号清理", businessType = BusinessType.UPDATE)
    @ApiOperation("拆码盘机任务完成编号清理")
    @PostMapping("/plcDishDeviceW")
    @ResponseBody
    public ResponseData cleanDishTaskNo(@RequestBody String deviceName) {
        log.info("清除设备" + deviceName + "的任务编号");
        DismountingDiskMachineOper cdm = (DismountingDiskMachineOper) Plc.deviceBaseNameMap.get(deviceName);
        PlcOper plcOper = PlcOperImpl.getPlcOper(cdm.getPlc());
        try {
            log.info("开始发送读取完成信号");
            plcOper.readComplete(cdm.getDeviceNo(), true);
            log.info("发送读取完成信号结束");
        } catch (IOException e) {
            return ResponseData.error("网络异常!任务完成编号清理失败!");
        }
        return ResponseData.success("任务完成编号清理完成!");
    }
/***************************************  移载机  ****************************/
    /**
     * 读取移裁机信息
     *
     * @param deviceId
     * @return
     */
    @PreAuthorize("@ss.hasPermi('plcDeviceDB:control')")
    @PostMapping("/plcTransPDevice")
    @ApiOperation("移裁机")
    @ResponseBody
    public ResponseData plcTransPDevice(@RequestBody Integer deviceId) {
        PlcDeviceDB plcDeviceDB = plcdevicedbService.getPlcDevById(deviceId);
        HandleTransP ht = plcdevicedbService.plcTransPDevice(deviceId);
        if (ht == null) {
            return ResponseData.error("系统中无名称为" + plcDeviceDB.getDeviceName() + "的设备,请确认后重试");
        }
        return ResponseData.success(ht);
    }

    /**
     * @param plcDeviceId
     * @return
     * @Description: 根据plcDeviceId获取移裁机
     */
    public TransPlanter getTPDevice(Integer plcDeviceId) {
        return (TransPlanter) Plc.deviceTransPlanterCoordMap.get(Node.parseGrid(plcDeviceDBServiceImpl.getById(plcDeviceId).getDeviceLocation()));
    }

    @PreAuthorize("@ss.hasPermi('transPlanter:initTransPlanter')")
    @Log(title = "移裁升降机管理", method = "设置移裁升降机类型", businessType = BusinessType.UPDATE)
    @GetMapping("/initTransPlanter")
    @ResponseBody
    @ApiOperation("设置移裁升降机类型")
    public ResponseData initTransPlanter(@RequestParam Integer plcDeviceId) throws IOException {
        try {
            log.info("接收到 设置 " + plcDeviceId + " 移裁升降机类型");
            plcDeviceDBServiceImpl.setDeviceType(this.getTPDevice(plcDeviceId));
            return ResponseData.success("设置自动升降机类型成功");
        } catch (Throwable e) {
            WcsFuncUtil.exceptionLog(e, this.getClass());
            return ResponseData.error("设置自动升降机类型失败");
        }
    }

    @PreAuthorize("@ss.hasPermi('transPlanter:setTransLiftAutoSpeed')")
    @Log(title = "移裁升降机管理", method = "设置升降自动速度", businessType = BusinessType.UPDATE)
    @GetMapping("/setTransLiftAutoSpeed")
    @ResponseBody
    @ApiOperation("设置升降自动速度")
    public ResponseData setTransLiftAutoSpeed(@RequestParam Integer plcDeviceId, @RequestParam Integer speed) throws IOException {
        try {
            log.info("接收到 设置 " + plcDeviceId + " 升降自动速度");
            if (speed == null) {
                return ResponseData.error("设置升降自动速度不能为空");
            } else if (speed < 1 || speed > 3000) {
                return ResponseData.error("升降自动速度值超出设置范围，设置范围在[1,3000]");
            }
            this.getTPDevice(plcDeviceId).setLiftAutoSpeed(speed);

            return ResponseData.success("设置升降自动速度成功", speed);
        } catch (Throwable e) {
            WcsFuncUtil.exceptionLog(e, this.getClass());
            return ResponseData.error("设置升降自动速度失败");
        }
    }

    @PreAuthorize("@ss.hasPermi('transPlanter:setTransLiftAutoAcc')")
    @Log(title = "移裁升降机管理", method = "设置升降自动加速时间", businessType = BusinessType.UPDATE)
    @GetMapping("/setTransLiftAutoAcc")
    @ResponseBody
    @ApiOperation("设置升降自动加速时间")
    public ResponseData setTransLiftAutoAcc(@RequestParam Integer plcDeviceId, @RequestParam Integer time) throws IOException {
        try {
            log.info("接收到 设置 " + plcDeviceId + " 升降自动加速时间");
            if (time == null) {
                return ResponseData.error("设置升降自动加速时间不能为空");
            } else if (time < 1 || time > 5000) {
                return ResponseData.error("升降自动加速时间超出设置范围，设置范围在[1,5000]");
            }
            this.getTPDevice(plcDeviceId).setLiftAutoAcc(time);

            return ResponseData.success("设置升降自动加速时间成功", time);
        } catch (Throwable e) {
            WcsFuncUtil.exceptionLog(e, this.getClass());
            return ResponseData.error("设置升降自动加速时间失败");
        }
    }

    @PreAuthorize("@ss.hasPermi('transPlanter:setTransLiftAutoDec')")
    @Log(title = "移裁升降机管理", method = "设置升降自动减速时间", businessType = BusinessType.UPDATE)
    @GetMapping("/setTransLiftAutoDec")
    @ResponseBody
    @ApiOperation("设置升降自动减速时间")
    public ResponseData setTransLiftAutoDec(@RequestParam Integer plcDeviceId, @RequestParam Integer time) throws IOException {
        try {
            log.info("接收到 设置 " + plcDeviceId + " 升降自动减速时间");
            if (time == null) {
                return ResponseData.error("设置升降自动减速时间不能为空");
            } else if (time < 1 || time > 5000) {
                return ResponseData.error("升降自动减速时间超出设置范围，设置范围在[1,5000]");
            }
            this.getTPDevice(plcDeviceId).setLiftAutoDec(time);

            return ResponseData.success("设置升降自动减速时间成功", time);
        } catch (Throwable e) {
            WcsFuncUtil.exceptionLog(e, this.getClass());
            return ResponseData.error("设置升降自动减速时间失败");
        }
    }

    @PreAuthorize("@ss.hasPermi('transPlanter:setTransLiftManualSpeed')")
    @Log(title = "移裁升降机管理", method = "设置升降手动速度", businessType = BusinessType.UPDATE)
    @GetMapping("/setTransLiftManualSpeed")
    @ResponseBody
    @ApiOperation("设置升降手动速度")
    public ResponseData setTransLiftManualSpeed(@RequestParam Integer plcDeviceId, @RequestParam Integer speed) throws IOException {
        try {
            log.info("接收到 设置 " + plcDeviceId + " 升降手动速度");
            if (speed == null) {
                return ResponseData.error("设置升降手动速度不能为空");
            } else if (speed < 1 || speed > 3000) {
                return ResponseData.error("升降手动速度值超出设置范围，设置范围在[1,3000]");
            }
            this.getTPDevice(plcDeviceId).setLiftManualSpeed(speed);

            return ResponseData.success("设置升降手动速度成功", speed);
        } catch (Throwable e) {
            WcsFuncUtil.exceptionLog(e, this.getClass());
            return ResponseData.error("设置升降手动速度失败");
        }
    }

    @PreAuthorize("@ss.hasPermi('transPlanter:setTransLiftManualAcc')")
    @Log(title = "移裁升降机管理", method = "设置升降手动加速时间", businessType = BusinessType.UPDATE)
    @GetMapping("/setTransLiftManualAcc")
    @ResponseBody
    @ApiOperation("设置升降手动加速时间")
    public ResponseData setTransLiftManualAcc(@RequestParam Integer plcDeviceId, @RequestParam Integer time) throws IOException {

        try {
            log.info("接收到 设置 " + plcDeviceId + " 升降手动加速时间");
            if (time == null) {
                return ResponseData.error("设置升降手动加速时间不能为空");
            } else if (time < 1 || time > 5000) {
                return ResponseData.error("升降手动加速时间超出设置范围，设置范围在[1,5000]");
            }
            this.getTPDevice(plcDeviceId).setLiftManualAcc(time);

            return ResponseData.success("设置升降手动加速时间成功", time);
        } catch (Throwable e) {
            WcsFuncUtil.exceptionLog(e, this.getClass());
            return ResponseData.error("设置升降手动加速时间失败");
        }
    }

    @PreAuthorize("@ss.hasPermi('transPlanter:setTransLiftManualDec')")
    @Log(title = "移裁升降机管理", method = "设置升降手动减速时间", businessType = BusinessType.UPDATE)
    @GetMapping("/setTransLiftManualDec")
    @ResponseBody
    @ApiOperation("设置升降手动减速时间")
    public ResponseData setTransLiftManualDec(@RequestParam Integer plcDeviceId, @RequestParam Integer time) throws IOException {
        try {
            log.info("接收到 设置 " + plcDeviceId + " 升降手动减速时间");
            if (time == null) {
                return ResponseData.error("设置升降手动减速时间不能为空");
            } else if (time < 1 || time > 5000) {
                return ResponseData.error("升降手动减速时间超出设置范围，设置范围在[1,5000]");
            }
            this.getTPDevice(plcDeviceId).setLiftManualDec(time);

            return ResponseData.success("设置升降手动减速时间成功", time);
        } catch (Throwable e) {
            WcsFuncUtil.exceptionLog(e, this.getClass());
            return ResponseData.error("设置升降手动减速时间失败");
        }
    }

    @PreAuthorize("@ss.hasPermi('transPlanter:setTransConveyorAutoSpeed')")
    @Log(title = "移裁升降机管理", method = "输送线自动速度", businessType = BusinessType.UPDATE)
    @GetMapping("/setTransConveyorAutoSpeed")
    @ResponseBody
    @ApiOperation("输送线自动速度")
    public ResponseData setTransConveyorAutoSpeed(@RequestParam Integer plcDeviceId, @RequestParam Integer speed) throws IOException {
        try {
            log.info("接收到 设置 " + plcDeviceId + " 输送线自动速度");
            if (speed == null) {
                return ResponseData.error("设置输送线自动速度不能为空");
            } else if (speed < 1 || speed > 3000) {
                return ResponseData.error("输送线自动速度值超出设置范围，设置范围在[1,3000]");
            }
            this.getTPDevice(plcDeviceId).setConveyorAutoSpeed(speed);

            return ResponseData.success("设置输送线自动速度成功", speed);
        } catch (Throwable e) {
            WcsFuncUtil.exceptionLog(e, this.getClass());
            return ResponseData.error("设置输送线自动速度失败");
        }
    }

    @PreAuthorize("@ss.hasPermi('transPlanter:setTransConveyorAutoAcc')")
    @Log(title = "移裁升降机管理", method = "输送线自动加速时间", businessType = BusinessType.UPDATE)
    @GetMapping("/setTransConveyorAutoAcc")
    @ResponseBody
    @ApiOperation("输送线自动加速时间")
    public ResponseData setTransConveyorAutoAcc(@RequestParam Integer plcDeviceId, @RequestParam Integer time) throws IOException {
        try {
            log.info("接收到 设置 " + plcDeviceId + " 输送线自动加速时间");
            if (time == null) {
                return ResponseData.error("设置输送线自动加速时间不能为空");
            } else if (time < 1 || time > 5000) {
                return ResponseData.error("输送线自动加速时间超出设置范围，设置范围在[1,5000]");
            }
            this.getTPDevice(plcDeviceId).setConveyorAutoAcc(time);

            return ResponseData.success("设置输送线自动加速时间成功", time);
        } catch (Throwable e) {
            WcsFuncUtil.exceptionLog(e, this.getClass());
            return ResponseData.error("设置输送线自动加速时间失败");
        }
    }

    @PreAuthorize("@ss.hasPermi('transPlanter:setTransConveyorAutoDec')")
    @Log(title = "移裁升降机管理", method = "输送线自动减速时间", businessType = BusinessType.UPDATE)
    @GetMapping("/setTransConveyorAutoDec")
    @ResponseBody
    @ApiOperation("输送线自动减速时间")
    public ResponseData setTransConveyorAutoDec(@RequestParam Integer plcDeviceId, @RequestParam Integer time) throws IOException {
        try {
            log.info("接收到 设置 " + plcDeviceId + " 输送线自动减速时间");
            if (time == null) {
                return ResponseData.error("设置输送线自动减速时间不能为空");
            } else if (time < 1 || time > 5000) {
                return ResponseData.error("输送线自动减速时间超出设置范围，设置范围在[1,5000]");
            }
            this.getTPDevice(plcDeviceId).setConveyorAutoDec(time);

            return ResponseData.success("设置输送线自动减速时间成功", time);
        } catch (Throwable e) {
            WcsFuncUtil.exceptionLog(e, this.getClass());
            return ResponseData.error("设置输送线自动减速时间失败");
        }
    }

    @PreAuthorize("@ss.hasPermi('transPlanter:setTransConveyorManualSpeed')")
    @Log(title = "移裁升降机管理", method = "输送线手动速度", businessType = BusinessType.UPDATE)
    @GetMapping("/setTransConveyorManualSpeed")
    @ResponseBody
    @ApiOperation("输送线手动速度")
    public ResponseData setTransConveyorManualSpeed(@RequestParam Integer plcDeviceId, @RequestParam Integer speed) throws IOException {
        try {
            log.info("接收到 设置 " + plcDeviceId + " 输送线手动速度");
            if (speed == null) {
                return ResponseData.error("设置输送线手动速度不能为空");
            } else if (speed < 1 || speed > 3000) {
                return ResponseData.error("输送线手动速度值超出设置范围，设置范围在[1,3000]");
            }
            this.getTPDevice(plcDeviceId).setConveyorManualSpeed(speed);

            return ResponseData.success("设置输送线手动速度成功", speed);
        } catch (Throwable e) {
            WcsFuncUtil.exceptionLog(e, this.getClass());
            return ResponseData.error("设置输送线手动速度失败");
        }
    }

    @PreAuthorize("@ss.hasPermi('transPlanter:setTransConveyorManualAcc')")
    @Log(title = "移裁升降机管理", method = "输送线手动加速时间", businessType = BusinessType.UPDATE)
    @GetMapping("/setTransConveyorManualAcc")
    @ResponseBody
    @ApiOperation("输送线手动加速时间")
    public ResponseData setTransConveyorManualAcc(@RequestParam Integer plcDeviceId, @RequestParam Integer time) throws IOException {
        try {
            log.info("接收到 设置 " + plcDeviceId + " 输送线手动加速时间");
            if (time == null) {
                return ResponseData.error("设置输送线手动加速时间不能为空");
            } else if (time < 1 || time > 5000) {
                return ResponseData.error("输送线手动加速时间超出设置范围，设置范围在[1,5000]");
            }
            this.getTPDevice(plcDeviceId).setConveyorManualAcc(time);

            return ResponseData.success("设置输送线手动加速时间成功", time);
        } catch (Throwable e) {
            WcsFuncUtil.exceptionLog(e, this.getClass());
            return ResponseData.error("设置输送线手动加速时间失败");
        }
    }

    @PreAuthorize("@ss.hasPermi('transPlanter:setTransConveyorManualDec')")
    @Log(title = "移裁升降机管理", method = "输送线手动减速时间", businessType = BusinessType.UPDATE)
    @GetMapping("/setTransConveyorManualDec")
    @ResponseBody
    @ApiOperation("输送线手动减速时间")
    public ResponseData setTransConveyorManualDec(@RequestParam Integer plcDeviceId, @RequestParam Integer time) throws IOException {
        try {
            log.info("接收到 设置 " + plcDeviceId + " 输送线手动减速时间");
            if (time == null) {
                return ResponseData.error("设置输送线手动减速时间不能为空");
            } else if (time < 1 || time > 5000) {
                return ResponseData.error("输送线手动减速时间超出设置范围，设置范围在[1,3000]");
            }
            this.getTPDevice(plcDeviceId).setConveyorManualDec(time);

            return ResponseData.success("设置输送线手动减速时间成功", time);
        } catch (Throwable e) {
            WcsFuncUtil.exceptionLog(e, this.getClass());
            return ResponseData.error("设置输送线手动减速时间失败");
        }
    }

    @PreAuthorize("@ss.hasPermi('transPlanter:platformTransRiseMovement')")
    @Log(title = "移裁升降机管理", method = "平台升位移量", businessType = BusinessType.UPDATE)
    @GetMapping("/platformTransRiseMovement")
    @ResponseBody
    @ApiOperation("平台升位移量")
    public ResponseData platformTransRiseMovement(@RequestParam Integer plcDeviceId) throws IOException {
        try {
            log.info("接收到 设置 " + plcDeviceId + " 平台升位移量");
            this.getTPDevice(plcDeviceId).setPlatformRiseMovement();

            return ResponseData.success("设置平台升位移量成功", null);
        } catch (Throwable e) {
            WcsFuncUtil.exceptionLog(e, this.getClass());
            return ResponseData.error("设置平台升位移量失败");
        }
    }

    @PreAuthorize("@ss.hasPermi('transPlanter:platformTransDropMovement')")
    @Log(title = "移裁升降机管理", method = "平台降位移量", businessType = BusinessType.UPDATE)
    @GetMapping("/platformTransDropMovement")
    @ResponseBody
    @ApiOperation("平台降位移量")
    public ResponseData platformTransDropMovement(@RequestParam Integer plcDeviceId) throws IOException {
        try {
            log.info("接收到 设置 " + plcDeviceId + " 平台降位移量");
            this.getTPDevice(plcDeviceId).setPlatformDropMovement();

            return ResponseData.success("设置平台降位移量成功", null);
        } catch (Throwable e) {
            WcsFuncUtil.exceptionLog(e, this.getClass());
            return ResponseData.error("设置平台降位移量失败");
        }
    }

    @PreAuthorize("@ss.hasPermi('transPlanter:platformTransRise')")
    @Log(title = "移裁升降机管理", method = "平台上升", businessType = BusinessType.UPDATE)
    @GetMapping("/platformTransRise")
    @ResponseBody
    @ApiOperation("平台上升")
    public ResponseData platformTransRise(@RequestParam Integer plcDeviceId) throws IOException {
        try {
            log.info("接收到 设置 " + plcDeviceId + " 平台上升");
            TransPlanter transPlanter = this.getTPDevice(plcDeviceId);
            if (!transPlanter.isControl()) {
                return ResponseData.error("设备未就绪");
            }
            if (transPlanter.isRiseInPlace()) {
                return ResponseData.error("平台已在上升位置");
            }
            transPlanter.platformRise();

            return ResponseData.success("平台上升成功", null);
        } catch (Throwable e) {
            WcsFuncUtil.exceptionLog(e, this.getClass());
            return ResponseData.error("平台上升失败");
        }
    }

    @PreAuthorize("@ss.hasPermi('transPlanter:platformTransDrop')")
    @Log(title = "移裁升降机管理", method = "平台下降", businessType = BusinessType.UPDATE)
    @GetMapping("/platformTransDrop")
    @ResponseBody
    @ApiOperation("平台下降")
    public ResponseData platformTransDrop(@RequestParam Integer plcDeviceId) throws IOException {
        try {
            log.info("接收到 设置 " + plcDeviceId + " 平台下降");
            TransPlanter transPlanter = this.getTPDevice(plcDeviceId);
            if (!transPlanter.isControl()) {
                return ResponseData.error("设备未就绪");
            }
            if (transPlanter.isDropInPlace()) {
                return ResponseData.error("平台已在下降位置");
            }
            transPlanter.platformDrop();

            return ResponseData.success("平台下降成功", null);
        } catch (Exception e) {
            WcsFuncUtil.exceptionLog(e, this.getClass());
            return ResponseData.error("平台下降失败");
        }
    }

    @PreAuthorize("@ss.hasPermi('transPlanter:platformTransForwardIn')")
    @Log(title = "移裁升降机管理", method = "正转入库", businessType = BusinessType.UPDATE)
    @GetMapping("/platformTransForwardIn")
    @ResponseBody
    @ApiOperation("正转入库")
    public ResponseData platformTransForwardIn(@RequestParam Integer plcDeviceId) throws IOException {
        try {
            log.info("接收到 设置 " + plcDeviceId + " 正转入库");
            TransPlanter transPlanter = this.getTPDevice(plcDeviceId);
            if (!transPlanter.isControl()) {
                return ResponseData.error("设备未就绪");
            }
            if (!transPlanter.isRiseInPlace() && !transPlanter.isDropInPlace()) {
                return ResponseData.error("平台未到位");
            }
            transPlanter.platformForwardIn();

            return ResponseData.success("正转入库成功", null);
        } catch (Exception e) {
            WcsFuncUtil.exceptionLog(e, this.getClass());
            return ResponseData.error("正转入库失败");
        }
    }

    @PreAuthorize("@ss.hasPermi('transPlanter:platformTransForwardOut')")
    @Log(title = "移裁升降机管理", method = "正转出库", businessType = BusinessType.UPDATE)
    @GetMapping("/platformTransForwardOut")
    @ResponseBody
    @ApiOperation("正转出库")
    public ResponseData platformTransForwardOut(@RequestParam Integer plcDeviceId) throws IOException {
        try {
            log.info("接收到 设置 " + plcDeviceId + " 正转出库");
            TransPlanter transPlanter = this.getTPDevice(plcDeviceId);
            if (!transPlanter.isControl()) {
                return ResponseData.error("设备未就绪");
            }
            if (!transPlanter.isRiseInPlace() && !transPlanter.isDropInPlace()) {
                return ResponseData.error("平台未到位");
            }
            transPlanter.platformForwardOut();

            return ResponseData.success("设置正转出库成功", null);
        } catch (Exception e) {
            WcsFuncUtil.exceptionLog(e, this.getClass());
            return ResponseData.error("设置正转出库失败");
        }
    }

    @PreAuthorize("@ss.hasPermi('transPlanter:platformTransReverseIn')")
    @Log(title = "移裁升降机管理", method = "反转入库", businessType = BusinessType.UPDATE)
    @GetMapping("/platformTransReverseIn")
    @ResponseBody
    @ApiOperation("反转入库")
    public ResponseData platformTransReverseIn(@RequestParam Integer plcDeviceId) throws IOException {
        try {
            log.info("接收到 设置 " + plcDeviceId + " 反转入库");
            TransPlanter transPlanter = this.getTPDevice(plcDeviceId);
            if (!transPlanter.isControl()) {
                return ResponseData.error("设备未就绪");
            }
            if (!transPlanter.isRiseInPlace() && !transPlanter.isDropInPlace()) {
                return ResponseData.error("平台未到位");
            }
            transPlanter.platformReverseIn();

            return ResponseData.success("设置反转入库成功", null);
        } catch (Exception e) {
            WcsFuncUtil.exceptionLog(e, this.getClass());
            return ResponseData.error("设置反转入库失败");
        }
    }

    @PreAuthorize("@ss.hasPermi('transPlanter:platformTransReverseOut')")
    @Log(title = "移裁升降机管理", method = "反转出库", businessType = BusinessType.UPDATE)
    @GetMapping("/platformTransReverseOut")
    @ResponseBody
    @ApiOperation("反转出库")
    public ResponseData platformTransReverseOut(@RequestParam Integer plcDeviceId) throws IOException {
        try {
            log.info("接收到 设置 " + plcDeviceId + " 反转出库");
            TransPlanter transPlanter = this.getTPDevice(plcDeviceId);
            if (!transPlanter.isControl()) {
                return ResponseData.error("设备未就绪");
            }
            if (!transPlanter.isRiseInPlace() && !transPlanter.isDropInPlace()) {
                return ResponseData.error("平台未到位");
            }
            transPlanter.platformReverseOut();

            return ResponseData.success("设置反转出库成功", null);
        } catch (Exception e) {
            WcsFuncUtil.exceptionLog(e, this.getClass());
            return ResponseData.error("设置反转出库失败");
        }
    }

    @PreAuthorize("@ss.hasPermi('transPlanter:clearErrorTransPlanter')")
    @Log(title = "移裁升降机管理", method = "移裁升降机故障清除", businessType = BusinessType.UPDATE)
    @GetMapping("/clearErrorTransPlanter")
    @ResponseBody
    @ApiOperation("移裁升降机故障清除")
    public ResponseData clearErrorTransPlanter(@RequestParam Integer plcDeviceId) throws IOException {
        try {
            log.info("接收到 设置 " + plcDeviceId + " 号移裁升降机故障清除信号");
            this.getTPDevice(plcDeviceId).setClearError();

            return ResponseData.success("移裁升降机故障清除成功", null);
        } catch (Exception e) {
            WcsFuncUtil.exceptionLog(e, this.getClass());
            return ResponseData.error("移裁升降机故障清除失败");
        }
    }

    /***************************************  自动横移机  ****************************/
    /**
     * 读取自动横移机信息
     *
     * @param deviceId
     * @return
     */
    @PreAuthorize("@ss.hasPermi('plcDeviceDB:control')")
    @PostMapping("/plcAutoTraversingDevice")
    @ApiOperation("自动横移机")
    @ResponseBody
    public ResponseData plcAutoTraversingDevice(@RequestBody Integer deviceId) {
        PlcDeviceDB plcDeviceDB = plcdevicedbService.getPlcDevById(deviceId);
        HandleAutoTraversingOper ht = SystemInit.plcAutoTraversingDevice(deviceId);
        if (ht == null) {
            return ResponseData.error("系统中无名称为" + plcDeviceDB.getDeviceName() + "的设备,请确认后重试");
        }
        return ResponseData.success(ht);
    }

    /**
     * @param plcDeviceId
     * @return
     * @Description: 根据plcDeviceId获取自动横移机
     */
    public AutoTraversingOper getATODevice(Integer plcDeviceId) {
        return (AutoTraversingOper) Plc.deviceAutoTraversingOperCoordMap.get(Node.parseGrid(plcDeviceDBServiceImpl.getById(plcDeviceId).getDeviceLocation()));
    }

    @PreAuthorize("@ss.hasPermi('autoTrversingOper:initAutoTraversing')")
    @Log(title = "自动横移机管理", method = "设置自动横移机类型", businessType = BusinessType.UPDATE)
    @GetMapping("/initAutoTraversing")
    @ResponseBody
    @ApiOperation("设置自动横移机类型")
    public ResponseData initAutoTraversing(@RequestParam Integer plcDeviceId) throws IOException {
        log.info("接收到 设置 " + plcDeviceId + " 自动横移机类型");
        plcDeviceDBServiceImpl.setDeviceType(this.getATODevice(plcDeviceId));
        return ResponseData.success("设置自动横移机类型成功");
    }

    @PreAuthorize("@ss.hasPermi('autoTrversingOper:setTraverseAutoSpeed')")
    @Log(title = "自动横移机管理", method = "设置横移自动速度", businessType = BusinessType.UPDATE)
    @GetMapping("/setTraverseAutoSpeed")
    @ResponseBody
    @ApiOperation("设置横移自动速度")
    public ResponseData setTraverseAutoSpeed(@RequestParam Integer plcDeviceId, @RequestParam Integer speed) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 升降自动速度");
        if (speed == null) {
            return ResponseData.error("设置横移自动速度不能为空");
        } else if (speed < 1 || speed > 3000) {
            return ResponseData.error("横移自动速度值超出设置范围，设置范围在[1,3000]");
        }
        plcDeviceDBServiceImpl.traverseAutoSpeed(this.getATODevice(plcDeviceId), speed);

        return ResponseData.success("设置横移自动速度成功", speed);
    }

    @PreAuthorize("@ss.hasPermi('autoTrversingOper:setTraverseAutoAcc')")
    @Log(title = "自动横移机管理", method = "设置横移自动加速时间", businessType = BusinessType.UPDATE)
    @GetMapping("/setTraverseAutoAcc")
    @ResponseBody
    @ApiOperation("设置横移自动加速时间")
    public ResponseData setTraverseAutoAcc(@RequestParam Integer plcDeviceId, @RequestParam Integer time) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 横移自动加速时间");
        if (time == null) {
            return ResponseData.error("设置横移自动加速时间不能为空");
        } else if (time < 1 || time > 5000) {
            return ResponseData.error("横移自动加速时间超出设置范围，设置范围在[1,5000]");
        }
        plcDeviceDBServiceImpl.traverseAutoAcc(this.getATODevice(plcDeviceId), time);

        return ResponseData.success("设置横移自动加速时间成功", time);
    }

    @PreAuthorize("@ss.hasPermi('autoTrversingOper:setTraverseAutoDec')")
    @Log(title = "自动横移机管理", method = "设置横移自动减速时间", businessType = BusinessType.UPDATE)
    @GetMapping("/setTraverseAutoDec")
    @ResponseBody
    @ApiOperation("设置横移自动减速时间")
    public ResponseData setTraverseAutoDec(@RequestParam Integer plcDeviceId, @RequestParam Integer time) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 横移自动减速时间");
        if (time == null) {
            return ResponseData.error("设置横移自动减速时间不能为空");
        } else if (time < 1 || time > 5000) {
            return ResponseData.error("横移自动减速时间超出设置范围，设置范围在[1,5000]");
        }
        plcDeviceDBServiceImpl.traverseAutoDec(this.getATODevice(plcDeviceId), time);

        return ResponseData.success("设置横移自动减速时间成功", time);
    }

    @PreAuthorize("@ss.hasPermi('autoTrversingOper:setTraverseManualSpeed')")
    @Log(title = "自动横移机管理", method = "设置横移手动速度", businessType = BusinessType.UPDATE)
    @GetMapping("/setTraverseManualSpeed")
    @ResponseBody
    @ApiOperation("设置横移手动速度")
    public ResponseData setTraverseManualSpeed(@RequestParam Integer plcDeviceId, @RequestParam Integer speed) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 横移手动速度");
        if (speed == null) {
            return ResponseData.error("设置横移手动速度不能为空");
        } else if (speed < 1 || speed > 3000) {
            return ResponseData.error("横移手动速度值超出设置范围，设置范围在[1,3000]");
        }
        plcDeviceDBServiceImpl.traverseManualSpeed(this.getATODevice(plcDeviceId), speed);

        return ResponseData.success("设置横移手动速度成功", speed);
    }

    @PreAuthorize("@ss.hasPermi('autoTrversingOper:setTraverseManualAcc')")
    @Log(title = "自动横移机管理", method = "设置横移手动加速时间", businessType = BusinessType.UPDATE)
    @GetMapping("/setTraverseManualAcc")
    @ResponseBody
    @ApiOperation("设置横移手动加速时间")
    public ResponseData setTraverseManualAcc(@RequestParam Integer plcDeviceId, @RequestParam Integer time) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 横移手动加速时间");
        if (time == null) {
            return ResponseData.error("设置横移手动加速时间不能为空");
        } else if (time < 1 || time > 5000) {
            return ResponseData.error("横移手动加速时间超出设置范围，设置范围在[1,5000]");
        }
        plcDeviceDBServiceImpl.traverseManualAcc(this.getATODevice(plcDeviceId), time);

        return ResponseData.success("设置横移手动加速时间成功", time);
    }

    @PreAuthorize("@ss.hasPermi('autoTrversingOper:setTraverseManualDec')")
    @Log(title = "自动横移机管理", method = "设置横移手动减速时间", businessType = BusinessType.UPDATE)
    @GetMapping("/setTraverseManualDec")
    @ResponseBody
    @ApiOperation("设置横移手动减速时间")
    public ResponseData setTraverseManualDec(@RequestParam Integer plcDeviceId, @RequestParam Integer time) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 横移手动减速时间");
        if (time == null) {
            return ResponseData.error("设置横移手动减速时间不能为空");
        } else if (time < 1 || time > 5000) {
            return ResponseData.error("横移手动减速时间超出设置范围，设置范围在[1,5000]");
        }
        plcDeviceDBServiceImpl.traverseManualDec(this.getATODevice(plcDeviceId), time);

        return ResponseData.success("设置横移手动减速时间成功", time);
    }

    @PreAuthorize("@ss.hasPermi('autoTrversingOper:setTraverseConveyorAutoSpeed')")
    @Log(title = "自动横移机管理", method = "输送线自动速度", businessType = BusinessType.UPDATE)
    @GetMapping("/setTraverseConveyorAutoSpeed")
    @ResponseBody
    @ApiOperation("输送线自动速度")
    public ResponseData setTraverseConveyorAutoSpeed(@RequestParam Integer plcDeviceId, @RequestParam Integer speed) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 输送线自动速度");
        if (speed == null) {
            return ResponseData.error("设置输送线自动速度不能为空");
        } else if (speed < 1 || speed > 3000) {
            return ResponseData.error("输送线自动速度值超出设置范围，设置范围在[1,3000]");
        }
        plcDeviceDBServiceImpl.traverseConveyorAutoSpeed(this.getATODevice(plcDeviceId), speed);

        return ResponseData.success("设置输送线自动速度成功", speed);
    }

    @PreAuthorize("@ss.hasPermi('autoTrversingOper:setTraverseConveyorAutoAcc')")
    @Log(title = "自动横移机管理", method = "输送线自动加速时间", businessType = BusinessType.UPDATE)
    @GetMapping("/setTraverseConveyorAutoAcc")
    @ResponseBody
    @ApiOperation("输送线自动加速时间")
    public ResponseData setTraverseConveyorAutoAcc(@RequestParam Integer plcDeviceId, @RequestParam Integer time) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 输送线自动加速时间");
        if (time == null) {
            return ResponseData.error("设置输送线自动加速时间不能为空");
        } else if (time < 1 || time > 5000) {
            return ResponseData.error("输送线自动加速时间超出设置范围，设置范围在[1,5000]");
        }
        plcDeviceDBServiceImpl.traverseConveyorAutoAcc(this.getATODevice(plcDeviceId), time);

        return ResponseData.success("设置输送线自动加速时间成功", time);
    }

    @PreAuthorize("@ss.hasPermi('autoTrversingOper:setTraverseConveyorAutoDec')")
    @Log(title = "自动横移机管理", method = "输送线自动减速时间", businessType = BusinessType.UPDATE)
    @GetMapping("/setTraverseConveyorAutoDec")
    @ResponseBody
    @ApiOperation("输送线自动减速时间")
    public ResponseData setTraverseConveyorAutoDec(@RequestParam Integer plcDeviceId, @RequestParam Integer time) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 输送线自动减速时间");
        if (time == null) {
            return ResponseData.error("设置输送线自动减速时间不能为空");
        } else if (time < 1 || time > 5000) {
            return ResponseData.error("输送线自动减速时间超出设置范围，设置范围在[1,5000]");
        }
        plcDeviceDBServiceImpl.traverseConveyorAutoDec(this.getATODevice(plcDeviceId), time);

        return ResponseData.success("设置输送线自动减速时间成功", time);
    }

    @PreAuthorize("@ss.hasPermi('autoTrversingOper:setTraverseConveyorManualSpeed')")
    @Log(title = "自动横移机管理", method = "输送线手动速度", businessType = BusinessType.UPDATE)
    @GetMapping("/setTraverseConveyorManualSpeed")
    @ResponseBody
    @ApiOperation("输送线手动速度")
    public ResponseData setTraverseConveyorManualSpeed(@RequestParam Integer plcDeviceId, @RequestParam Integer speed) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 输送线手动速度");
        if (speed == null) {
            return ResponseData.error("设置输送线手动速度不能为空");
        } else if (speed < 1 || speed > 3000) {
            return ResponseData.error("输送线手动速度值超出设置范围，设置范围在[1,3000]");
        }
        plcDeviceDBServiceImpl.traverseConveyorManualSpeed(this.getATODevice(plcDeviceId), speed);

        return ResponseData.success("设置输送线手动速度成功", speed);
    }

    @PreAuthorize("@ss.hasPermi('autoTrversingOper:setTraverseConveyorManualAcc')")
    @Log(title = "自动横移机管理", method = "输送线手动加速时间", businessType = BusinessType.UPDATE)
    @GetMapping("/setTraverseConveyorManualAcc")
    @ResponseBody
    @ApiOperation("输送线手动加速时间")
    public ResponseData setTraverseConveyorManualAcc(@RequestParam Integer plcDeviceId, @RequestParam Integer time) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 输送线手动加速时间");
        if (time == null) {
            return ResponseData.error("设置输送线手动加速时间不能为空");
        } else if (time < 1 || time > 5000) {
            return ResponseData.error("输送线手动加速时间超出设置范围，设置范围在[1,5000]");
        }
        plcDeviceDBServiceImpl.traverseConveyorManualAcc(this.getATODevice(plcDeviceId), time);

        return ResponseData.success("设置输送线手动加速时间成功", time);
    }

    @PreAuthorize("@ss.hasPermi('autoTrversingOper:setTraverseConveyorManualDec')")
    @Log(title = "自动横移机管理", method = "输送线手动减速时间", businessType = BusinessType.UPDATE)
    @GetMapping("/setTraverseConveyorManualDec")
    @ResponseBody
    @ApiOperation("输送线手动减速时间")
    public ResponseData setTraverseConveyorManualDec(@RequestParam Integer plcDeviceId, @RequestParam Integer time) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 输送线手动减速时间");
        if (time == null) {
            return ResponseData.error("设置输送线手动减速时间不能为空");
        } else if (time < 1 || time > 5000) {
            return ResponseData.error("输送线手动减速时间超出设置范围，设置范围在[1,3000]");
        }
        plcDeviceDBServiceImpl.traverseConveyorManualDec(this.getATODevice(plcDeviceId), time);

        return ResponseData.success("设置输送线手动减速时间成功", time);
    }

    @PreAuthorize("@ss.hasPermi('autoTrversingOper:conveyorForward')")
    @Log(title = "自动横移机管理", method = "横移机正转", businessType = BusinessType.UPDATE)
    @GetMapping("/conveyorForward")
    @ResponseBody
    @ApiOperation("横移机正转")
    public ResponseData conveyorForward(@RequestParam Integer plcDeviceId) throws IOException {

        log.info("接收到" + plcDeviceId + " 横移机正转");
        AutoTraversingOper autoTraversingOper = this.getATODevice(plcDeviceId);
        if (autoTraversingOper == null) {
            return ResponseData.error("设备离线");
        }
        if (!autoTraversingOper.isControl()) {
            return ResponseData.error("设备未就绪");
        }
        if (autoTraversingOper.isRunning()) {
            return ResponseData.error("横移机运行中！");
        }
        plcDeviceDBServiceImpl.singleConveyorForward(this.getATODevice(plcDeviceId));

        return ResponseData.success("横移机正转，横移机输送线正转下发成功", null);
    }

    @PreAuthorize("@ss.hasPermi('autoTrversingOper:conveyorReserve')")
    @Log(title = "自动横移机管理", method = "输送线反转", businessType = BusinessType.UPDATE)
    @GetMapping("/conveyorReserve")
    @ResponseBody
    @ApiOperation("输送线反转")
    public ResponseData conveyorReserve(@RequestParam Integer plcDeviceId) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 单体输送线反转");
        AutoTraversingOper autoTraversingOper = this.getATODevice(plcDeviceId);
        if (autoTraversingOper == null) {
            return ResponseData.error("设备离线");
        }
        if (!autoTraversingOper.isControl()) {
            return ResponseData.error("设备未就绪");
        }
        if (autoTraversingOper.isRunning()) {
            return ResponseData.error("横移机运行中！");
        }
        plcDeviceDBServiceImpl.singleConveyorReverse(this.getATODevice(plcDeviceId));

        return ResponseData.success("输送线反转，横移机输送线反转下发成功", null);
    }

    @PreAuthorize("@ss.hasPermi('autoTrversingOper:conveyorStop')")
    @Log(title = "自动横移机管理", method = "输送线停止", businessType = BusinessType.UPDATE)
    @GetMapping("/conveyorStop")
    @ResponseBody
    @ApiOperation("输送线停止")
    public ResponseData conveyorStop(@RequestParam Integer plcDeviceId) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 输送线停止");
        AutoTraversingOper autoTraversingOper = this.getATODevice(plcDeviceId);
        if (autoTraversingOper == null) {
            return ResponseData.error("设备离线");
        }
        if (!autoTraversingOper.isControl()) {
            return ResponseData.error("设备未就绪");
        }
        plcDeviceDBServiceImpl.singleConveyorStop(this.getATODevice(plcDeviceId));

        return ResponseData.success("输送线停止，横移机输送线停止下发成功", null);
    }

    @PreAuthorize("@ss.hasPermi('autoTrversingOper:conveyor3In')")
    @Log(title = "自动横移机管理", method = "3#入库", businessType = BusinessType.UPDATE)
    @GetMapping("/conveyor3In")
    @ResponseBody
    @ApiOperation("3#入库")
    public ResponseData conveyor3In(@RequestParam Integer plcDeviceId) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 横移机输送线正转");
        AutoTraversingOper autoTraversingOper = this.getATODevice(plcDeviceId);
        if (autoTraversingOper == null) {
            return ResponseData.error("设备离线");
        }
        if (!autoTraversingOper.isControl()) {
            return ResponseData.error("设备未就绪");
        }
        if (autoTraversingOper.inCargoSignal() || autoTraversingOper.outCargoSignal()) {
            return ResponseData.error("横移机上有货，无法入库！");
        }
        if (!autoTraversingOper.isAutoDoorRise3()) {
            return ResponseData.error("横移机上3#自动门未升到位，无法入库！");
        }
        if (!autoTraversingOper.isInPlaceSignal3()) {
            return ResponseData.error("横移机上3未到位，无法入库！");
        }
        plcDeviceDBServiceImpl.traverseConveyorForward(this.getATODevice(plcDeviceId));

        return ResponseData.success("横移机输送线正转成功", null);
    }

    @PreAuthorize("@ss.hasPermi('autoTrversingOper:conveyor3Out')")
    @Log(title = "自动横移机管理", method = "3#出库", businessType = BusinessType.UPDATE)
    @GetMapping("/conveyor3Out")
    @ResponseBody
    @ApiOperation("3#出库")
    public ResponseData conveyor3Out(@RequestParam Integer plcDeviceId) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 横移机输送线反转");
        AutoTraversingOper autoTraversingOper = this.getATODevice(plcDeviceId);
        if (autoTraversingOper == null) {
            return ResponseData.error("设备离线");
        }
        if (!autoTraversingOper.isControl()) {
            return ResponseData.error("设备未就绪");
        }
        if (!autoTraversingOper.inCargoSignal() || !autoTraversingOper.outCargoSignal()) {
            return ResponseData.error("横移机上无货，无法出库！");
        }
        if (!autoTraversingOper.isAutoDoorRise3()) {
            return ResponseData.error("横移机上3#自动门未升到位，无法出库！");
        }
        if (!autoTraversingOper.isInPlaceSignal3()) {
            return ResponseData.error("横移机上3未到位，无法入库！");
        }
        plcDeviceDBServiceImpl.traverseConveyorReverse(this.getATODevice(plcDeviceId));

        return ResponseData.success("横移机输送线反转成功", null);
    }

    @PreAuthorize("@ss.hasPermi('autoTrversingOper:door1Forward')")
    @Log(title = "自动横移机管理", method = "自动门1正转", businessType = BusinessType.UPDATE)
    @GetMapping("/door1Forward")
    @ResponseBody
    @ApiOperation("自动门1正转")
    public ResponseData door1Forward(@RequestParam Integer plcDeviceId) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 自动门1正转");
        AutoTraversingOper autoTraversingOper = this.getATODevice(plcDeviceId);
        if (autoTraversingOper == null) {
            return ResponseData.error("设备离线");
        }
        if (!autoTraversingOper.isControl()) {
            return ResponseData.error("设备未就绪");
        }
        if (!autoTraversingOper.isInMidPlace()) {
            return ResponseData.error("横移机未在原点，自动门无法上升");
        }
        plcDeviceDBServiceImpl.door1Forward(this.getATODevice(plcDeviceId));

        return ResponseData.success("自动门1正转成功", null);
    }

    @PreAuthorize("@ss.hasPermi('autoTrversingOper:door1Reverse')")
    @Log(title = "自动横移机管理", method = "自动门1反转", businessType = BusinessType.UPDATE)
    @GetMapping("/door1Reverse")
    @ResponseBody
    @ApiOperation("自动门1反转")
    public ResponseData door1Reverse(@RequestParam Integer plcDeviceId) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 反转出库");
        AutoTraversingOper autoTraversingOper = this.getATODevice(plcDeviceId);
        if (autoTraversingOper == null) {
            return ResponseData.error("设备离线");
        }
        if (!autoTraversingOper.isControl()) {
            return ResponseData.error("设备未就绪");
        }
        if (!autoTraversingOper.isInMidPlace()) {
            return ResponseData.error("横移机未在原点，自动门无法下降");
        }
        plcDeviceDBServiceImpl.door1Reverse(this.getATODevice(plcDeviceId));

        return ResponseData.success("设置反转出库成功", null);
    }

    @PreAuthorize("@ss.hasPermi('autoTrversingOper:door3Forward')")
    @Log(title = "自动横移机管理", method = "自动门3正转", businessType = BusinessType.UPDATE)
    @GetMapping("/door3Forward")
    @ResponseBody
    @ApiOperation("自动门3正转")
    public ResponseData door3Forward(@RequestParam Integer plcDeviceId) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 自动门3正转");
        AutoTraversingOper autoTraversingOper = this.getATODevice(plcDeviceId);
        if (autoTraversingOper == null) {
            return ResponseData.error("设备离线");
        }
        if (!autoTraversingOper.isControl()) {
            return ResponseData.error("设备未就绪");
        }
        if (!autoTraversingOper.isInMidPlace()) {
            return ResponseData.error("横移机未在原点，自动门无法上升");
        }
        plcDeviceDBServiceImpl.door3Forward(this.getATODevice(plcDeviceId));

        return ResponseData.success("自动门3正转成功", null);
    }

    @PreAuthorize("@ss.hasPermi('autoTrversingOper:door3Reverse')")
    @Log(title = "自动横移机管理", method = "自动门3反转", businessType = BusinessType.UPDATE)
    @GetMapping("/door3Reverse")
    @ResponseBody
    @ApiOperation("自动门3反转")
    public ResponseData door3Reverse(@RequestParam Integer plcDeviceId) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 自动门3反转");
        AutoTraversingOper autoTraversingOper = this.getATODevice(plcDeviceId);
        if (autoTraversingOper == null) {
            return ResponseData.error("设备离线");
        }
        if (!autoTraversingOper.isControl()) {
            return ResponseData.error("设备未就绪");
        }
        if (!autoTraversingOper.isInMidPlace()) {
            return ResponseData.error("横移机未在原点，自动门无法下降");
        }
        plcDeviceDBServiceImpl.door3Reverse(this.getATODevice(plcDeviceId));

        return ResponseData.success("设置自动门3反转成功", null);
    }

    @PreAuthorize("@ss.hasPermi('autoTrversingOper:platformTraverseLeft')")
    @Log(title = "自动横移机管理", method = "平台左横移", businessType = BusinessType.UPDATE)
    @GetMapping("/platformTraverseLeft")
    @ResponseBody
    @ApiOperation("平台左横移")
    public ResponseData platformTraverseLeft(@RequestParam Integer plcDeviceId) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 平台左横移");
        AutoTraversingOper autoTraversingOper = this.getATODevice(plcDeviceId);
        if (autoTraversingOper == null) {
            return ResponseData.error("设备离线");
        }
        if (!autoTraversingOper.isControl()) {
            return ResponseData.error("设备未就绪");
        }
        if (!autoTraversingOper.isAutoDoorRise1()) {
            return ResponseData.error("自动门未升到位，横移机无法横移");
        }
        plcDeviceDBServiceImpl.platformLeftTraverse(this.getATODevice(plcDeviceId));

        return ResponseData.success("设置平台左横移成功", null);
    }

    @PreAuthorize("@ss.hasPermi('autoTrversingOper:platformTraverseRight')")
    @Log(title = "自动横移机管理", method = "平台右横移", businessType = BusinessType.UPDATE)
    @GetMapping("/platformTraverseRight")
    @ResponseBody
    @ApiOperation("平台右横移")
    public ResponseData platformTraverseRight(@RequestParam Integer plcDeviceId) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 平台右横移");
        AutoTraversingOper autoTraversingOper = this.getATODevice(plcDeviceId);
        if (autoTraversingOper == null) {
            return ResponseData.error("设备离线");
        }
        if (!autoTraversingOper.isControl()) {
            return ResponseData.error("设备未就绪");
        }
        if (!autoTraversingOper.isAutoDoorRise3()) {
            return ResponseData.error("自动门未升到位，横移机无法横移");
        }
        plcDeviceDBServiceImpl.platformRightTraverse(this.getATODevice(plcDeviceId));

        return ResponseData.success("设置平台右横移成功", null);
    }

    @PreAuthorize("@ss.hasPermi('autoTrversingOper:platformTraverseInSitu')")
    @Log(title = "自动横移机管理", method = "平台原位", businessType = BusinessType.UPDATE)
    @GetMapping("/platformTraverseInSitu")
    @ResponseBody
    @ApiOperation("平台原位")
    public ResponseData platformTraverseInSitu(@RequestParam Integer plcDeviceId) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 平台原位");

        plcDeviceDBServiceImpl.platformInSituTraverse(this.getATODevice(plcDeviceId));

        return ResponseData.success("设置平台原位成功", null);
    }


    @PreAuthorize("@ss.hasPermi('autoTrversingOper:clearError')")
    @Log(title = "自动横移机管理", method = "自动横移机故障清除", businessType = BusinessType.UPDATE)
    @GetMapping("/clearErrorAutoTraversing")
    @ResponseBody
    @ApiOperation("自动横移机故障清除")
    public ResponseData clearTraverseError(@RequestParam Integer plcDeviceId) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 号自动横移机故障清除信号");

        plcDeviceDBServiceImpl.traverseClearError(this.getATODevice(plcDeviceId));

        return ResponseData.success("自动横移机故障清除成功", null);
    }
    /***************************************  自动升降机  ****************************/
    /**
     * 读取自动升降机信息
     *
     * @param deviceId
     * @return
     */
    @PreAuthorize("@ss.hasPermi('plcDeviceDB:control')")
    @PostMapping("/plcAutoHoistDevice")
    @ApiOperation("自动升降机")
    @ResponseBody
    public ResponseData plcAutoHoistDevice(@RequestBody Integer deviceId) {
        PlcDeviceDB plcDeviceDB = plcdevicedbService.getPlcDevById(deviceId);
        HandleAutoHoistOper ht = plcdevicedbService.plcAutoHoistDevice(deviceId);
        if (ht == null) {
            return ResponseData.error("系统中无名称为" + plcDeviceDB.getDeviceName() + "的设备,请确认后重试");
        }
        return ResponseData.success(ht);
    }

    /***************************************  牙叉升降机  ****************************/
    /**
     * 读取牙叉升降机信息
     *
     * @param deviceId
     * @return
     */
    @PreAuthorize("@ss.hasPermi('plcDeviceDB:control')")
    @PostMapping("/plcToothHoistDevice")
    @ApiOperation("牙叉升降机")
    @ResponseBody
    public ResponseData plcToothHoistDevice(@RequestBody Integer deviceId) {
        PlcDeviceDB plcDeviceDB = plcdevicedbService.getPlcDevById(deviceId);
        HandleToothHoistOper ht = SystemInit.plcToothHoistDevice(deviceId);
        if (ht == null) {
            return ResponseData.error("系统中无名称为" + plcDeviceDB.getDeviceName() + "的设备,请确认后重试");
        }
        return ResponseData.success(ht);
    }

    /**
     * @param plcDeviceId
     * @return
     * @Description: 根据plcDeviceId获取牙叉升降机
     */
    public ToothHoistOper getTHODevice(Integer plcDeviceId) {
        return (ToothHoistOper) Plc.deviceToothHoistOperCoordMap.get(Node.parseGrid(plcDeviceDBServiceImpl.getById(plcDeviceId).getDeviceLocation()));
    }

    @PreAuthorize("@ss.hasPermi('toothHoistOper:initToothElevator')")
    @Log(title = "自动升降机管理", method = "设置牙叉升降机类型", businessType = BusinessType.UPDATE)
    @GetMapping("/initToothElevator")
    @ResponseBody
    @ApiOperation("设置牙叉升降机类型")
    public ResponseData initToothElevator(@RequestParam Integer plcDeviceId) throws IOException {
        log.info("接收到 设置 " + plcDeviceId + " 牙叉升降机类型");
        plcDeviceDBServiceImpl.setDeviceType(this.getTHODevice(plcDeviceId));
        return ResponseData.success("设置自动升降机类型成功");
    }

    @PreAuthorize("@ss.hasPermi('toothHoistOper:setToothLiftAutoSpeed')")
    @Log(title = "牙叉升降机管理", method = "设置升降自动速度", businessType = BusinessType.UPDATE)
    @GetMapping("/setToothLiftAutoSpeed")
    @ResponseBody
    @ApiOperation("设置升降自动速度")
    public ResponseData setToothLiftAutoSpeed(@RequestParam Integer plcDeviceId, @RequestParam Integer speed) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 升降自动速度");
        if (speed == null) {
            return ResponseData.error("设置升降自动速度不能为空");
        } else if (speed < 1 || speed > 3000) {
            return ResponseData.error("升降自动速度值超出设置范围，设置范围在[1,3000]");
        }
        plcdevicedbService.toothHoistLiftAutoSpeed(this.getTHODevice(plcDeviceId), speed);

        return ResponseData.success("设置升降自动速度成功", speed);
    }

    @PreAuthorize("@ss.hasPermi('toothHoistOper:setToothLiftAutoAcc')")
    @Log(title = "牙叉升降机管理", method = "设置升降自动加速时间", businessType = BusinessType.UPDATE)
    @GetMapping("/setToothLiftAutoAcc")
    @ResponseBody
    @ApiOperation("设置升降自动加速时间")
    public ResponseData setToothLiftAutoAcc(@RequestParam Integer plcDeviceId, @RequestParam Integer time) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 升降自动加速时间");
        if (time == null) {
            return ResponseData.error("设置升降自动加速时间不能为空");
        } else if (time < 1 || time > 5000) {
            return ResponseData.error("升降自动加速时间超出设置范围，设置范围在[1,5000]");
        }
        plcdevicedbService.toothHoistLiftAutoAcc(this.getTHODevice(plcDeviceId), time);

        return ResponseData.success("设置升降自动加速时间成功", time);
    }

    @PreAuthorize("@ss.hasPermi('toothHoistOper:setToothLiftAutoDec')")
    @Log(title = "牙叉升降机管理", method = "设置升降自动减速时间", businessType = BusinessType.UPDATE)
    @GetMapping("/setToothLiftAutoDec")
    @ResponseBody
    @ApiOperation("设置升降自动减速时间")
    public ResponseData setToothLiftAutoDec(@RequestParam Integer plcDeviceId, @RequestParam Integer time) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 升降自动减速时间");
        if (time == null) {
            return ResponseData.error("设置升降自动减速时间不能为空");
        } else if (time < 1 || time > 5000) {
            return ResponseData.error("升降自动减速时间超出设置范围，设置范围在[1,5000]");
        }
        plcdevicedbService.toothHoistLiftAutoDec(this.getTHODevice(plcDeviceId), time);

        return ResponseData.success("设置升降自动减速时间成功", time);
    }

    @PreAuthorize("@ss.hasPermi('toothHoistOper:setToothLiftManualSpeed')")
    @Log(title = "牙叉升降机管理", method = "设置升降手动速度", businessType = BusinessType.UPDATE)
    @GetMapping("/setToothLiftManualSpeed")
    @ResponseBody
    @ApiOperation("设置升降手动速度")
    public ResponseData setToothLiftManualSpeed(@RequestParam Integer plcDeviceId, @RequestParam Integer speed) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 升降手动速度");
        if (speed == null) {
            return ResponseData.error("设置升降手动速度不能为空");
        } else if (speed < 1 || speed > 3000) {
            return ResponseData.error("升降手动速度值超出设置范围，设置范围在[1,3000]");
        }
        plcdevicedbService.toothHoistLiftManualSpeed(this.getTHODevice(plcDeviceId), speed);

        return ResponseData.success("设置升降手动速度成功", speed);
    }

    @PreAuthorize("@ss.hasPermi('toothHoistOper:setToothLiftManualAcc')")
    @Log(title = "牙叉升降机管理", method = "设置升降手动加速时间", businessType = BusinessType.UPDATE)
    @GetMapping("/setToothLiftManualAcc")
    @ResponseBody
    @ApiOperation("设置升降手动加速时间")
    public ResponseData setToothLiftManualAcc(@RequestParam Integer plcDeviceId, @RequestParam Integer time) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 升降手动加速时间");
        if (time == null) {
            return ResponseData.error("设置升降手动加速时间不能为空");
        } else if (time < 1 || time > 5000) {
            return ResponseData.error("升降手动加速时间超出设置范围，设置范围在[1,5000]");
        }
        plcdevicedbService.toothHoistLiftManualAcc(this.getTHODevice(plcDeviceId), time);

        return ResponseData.success("设置升降手动加速时间成功", time);
    }

    @PreAuthorize("@ss.hasPermi('toothHoistOper:setToothLiftManualDec')")
    @Log(title = "牙叉升降机管理", method = "设置升降手动减速时间", businessType = BusinessType.UPDATE)
    @GetMapping("/setToothLiftManualDec")
    @ResponseBody
    @ApiOperation("设置升降手动减速时间")
    public ResponseData setToothLiftManualDec(@RequestParam Integer plcDeviceId, @RequestParam Integer time) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 升降手动减速时间");
        if (time == null) {
            return ResponseData.error("设置升降手动减速时间不能为空");
        } else if (time < 1 || time > 5000) {
            return ResponseData.error("升降手动减速时间超出设置范围，设置范围在[1,5000]");
        }
        plcdevicedbService.toothHoistLiftManualDec(this.getTHODevice(plcDeviceId), time);

        return ResponseData.success("设置升降手动减速时间成功", time);
    }

    @PreAuthorize("@ss.hasPermi('toothHoistOper:setToothConveyorAutoSpeed')")
    @Log(title = "牙叉升降机管理", method = "输送线自动速度", businessType = BusinessType.UPDATE)
    @GetMapping("/setToothConveyorAutoSpeed")
    @ResponseBody
    @ApiOperation("输送线自动速度")
    public ResponseData setToothConveyorAutoSpeed(@RequestParam Integer plcDeviceId, @RequestParam Integer speed) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 输送线自动速度");
        if (speed == null) {
            return ResponseData.error("设置输送线自动速度不能为空");
        } else if (speed < 1 || speed > 3000) {
            return ResponseData.error("输送线自动速度值超出设置范围，设置范围在[1,3000]");
        }
        plcdevicedbService.toothHoistConveyorAutoSpeed(this.getTHODevice(plcDeviceId), speed);

        return ResponseData.success("设置输送线自动速度成功", speed);
    }

    @PreAuthorize("@ss.hasPermi('toothHoistOper:setToothConveyorAutoAcc')")
    @Log(title = "牙叉升降机管理", method = "输送线自动加速时间", businessType = BusinessType.UPDATE)
    @GetMapping("/setToothConveyorAutoAcc")
    @ResponseBody
    @ApiOperation("输送线自动加速时间")
    public ResponseData setToothConveyorAutoAcc(@RequestParam Integer plcDeviceId, @RequestParam Integer time) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 输送线自动加速时间");
        if (time == null) {
            return ResponseData.error("设置输送线自动加速时间不能为空");
        } else if (time < 1 || time > 5000) {
            return ResponseData.error("输送线自动加速时间超出设置范围，设置范围在[1,5000]");
        }
        plcdevicedbService.toothHoistConveyorAutoAcc(this.getTHODevice(plcDeviceId), time);

        return ResponseData.success("设置输送线自动加速时间成功", time);
    }

    @PreAuthorize("@ss.hasPermi('toothHoistOper:setToothConveyorAutoDec')")
    @Log(title = "牙叉升降机管理", method = "输送线自动减速时间", businessType = BusinessType.UPDATE)
    @GetMapping("/setToothConveyorAutoDec")
    @ResponseBody
    @ApiOperation("输送线自动减速时间")
    public ResponseData setToothConveyorAutoDec(@RequestParam Integer plcDeviceId, @RequestParam Integer time) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 输送线自动减速时间");
        if (time == null) {
            return ResponseData.error("设置输送线自动减速时间不能为空");
        } else if (time < 1 || time > 5000) {
            return ResponseData.error("输送线自动减速时间超出设置范围，设置范围在[1,5000]");
        }
        plcdevicedbService.toothHoistConveyorAutoDec(this.getTHODevice(plcDeviceId), time);

        return ResponseData.success("设置输送线自动减速时间成功", time);
    }

    @PreAuthorize("@ss.hasPermi('toothHoistOper:setToothConveyorManualSpeed')")
    @Log(title = "牙叉升降机管理", method = "输送线手动速度", businessType = BusinessType.UPDATE)
    @GetMapping("/setToothConveyorManualSpeed")
    @ResponseBody
    @ApiOperation("输送线手动速度")
    public ResponseData setToothConveyorManualSpeed(@RequestParam Integer plcDeviceId, @RequestParam Integer speed) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 输送线手动速度");
        if (speed == null) {
            return ResponseData.error("设置输送线手动速度不能为空");
        } else if (speed < 1 || speed > 3000) {
            return ResponseData.error("输送线手动速度值超出设置范围，设置范围在[1,3000]");
        }
        plcdevicedbService.toothHoistConveyorManualSpeed(this.getTHODevice(plcDeviceId), speed);

        return ResponseData.success("设置输送线手动速度成功", speed);
    }

    @PreAuthorize("@ss.hasPermi('toothHoistOper:setToothConveyorManualAcc')")
    @Log(title = "牙叉升降机管理", method = "输送线手动加速时间", businessType = BusinessType.UPDATE)
    @GetMapping("/setToothConveyorManualAcc")
    @ResponseBody
    @ApiOperation("输送线手动加速时间")
    public ResponseData setToothConveyorManualAcc(@RequestParam Integer plcDeviceId, @RequestParam Integer time) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 输送线手动加速时间");
        if (time == null) {
            return ResponseData.error("设置输送线手动加速时间不能为空");
        } else if (time < 1 || time > 5000) {
            return ResponseData.error("输送线手动加速时间超出设置范围，设置范围在[1,5000]");
        }
        plcdevicedbService.toothHoistConveyorManualAcc(this.getTHODevice(plcDeviceId), time);

        return ResponseData.success("设置输送线手动加速时间成功", time);
    }

    @PreAuthorize("@ss.hasPermi('toothHoistOper:setToothConveyorManualDec')")
    @Log(title = "牙叉升降机管理", method = "输送线手动减速时间", businessType = BusinessType.UPDATE)
    @GetMapping("/setToothConveyorManualDec")
    @ResponseBody
    @ApiOperation("输送线手动减速时间")
    public ResponseData setToothConveyorManualDec(@RequestParam Integer plcDeviceId, @RequestParam Integer time) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 输送线手动减速时间");
        if (time == null) {
            return ResponseData.error("设置输送线手动减速时间不能为空");
        } else if (time < 1 || time > 5000) {
            return ResponseData.error("输送线手动减速时间超出设置范围，设置范围在[1,3000]");
        }
        plcdevicedbService.toothHoistConveyorManualDec(this.getTHODevice(plcDeviceId), time);

        return ResponseData.success("设置输送线手动减速时间成功", time);
    }

    @PreAuthorize("@ss.hasPermi('toothHoistOper:platformToothRiseMovement')")
    @Log(title = "牙叉升降机管理", method = "平台升位移量", businessType = BusinessType.UPDATE)
    @GetMapping("/platformToothRiseMovement")
    @ResponseBody
    @ApiOperation("平台升位移量")
    public ResponseData platformToothRiseMovement(@RequestParam Integer plcDeviceId) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 平台升位移量");
        ToothHoistOper toothHoistOper = this.getTHODevice(plcDeviceId);
        if (!toothHoistOper.isControl()) {
            return ResponseData.error("设备未就绪");
        }
        if (!toothHoistOper.isRiseInPlace()) {
            return ResponseData.error("设备未在升到位的位置");
        }
        plcdevicedbService.toothHoistRiseMovement(this.getTHODevice(plcDeviceId));

        return ResponseData.success("设置平台升位移量成功", null);
    }

    @PreAuthorize("@ss.hasPermi('toothHoistOper:platformToothDropMovement')")
    @Log(title = "牙叉升降机管理", method = "平台降位移量", businessType = BusinessType.UPDATE)
    @GetMapping("/platformToothDropMovement")
    @ResponseBody
    @ApiOperation("平台降位移量")
    public ResponseData platformToothDropMovement(@RequestParam Integer plcDeviceId) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 平台降位移量");
        ToothHoistOper toothHoistOper = this.getTHODevice(plcDeviceId);
        if (!toothHoistOper.isControl()) {
            return ResponseData.error("设备未就绪");
        }
        if (!toothHoistOper.isDropInPlace()) {
            return ResponseData.error("设备未在降到位的位置");
        }
        plcdevicedbService.toothHoistDropMovement(this.getTHODevice(plcDeviceId));

        return ResponseData.success("设置平台降位移量成功", null);
    }

    @PreAuthorize("@ss.hasPermi('toothHoistOper:platformRise')")
    @Log(title = "牙叉升降机管理", method = "平台上升", businessType = BusinessType.UPDATE)
    @GetMapping("/platformRise")
    @ResponseBody
    @ApiOperation("平台上升")
    public ResponseData platformRise(@RequestParam Integer plcDeviceId) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 平台上升");
        ToothHoistOper toothHoistOper = this.getTHODevice(plcDeviceId);
        if (!toothHoistOper.isControl()) {
            return ResponseData.error("设备未就绪");
        }
        if (toothHoistOper.isRiseInPlace()) {
            return ResponseData.error("平台已在上升位置");
        }
        plcdevicedbService.platformRise(this.getTHODevice(plcDeviceId));

        return ResponseData.success("平台上升成功", null);
    }

    @PreAuthorize("@ss.hasPermi('toothHoistOper:platformDrop')")
    @Log(title = "牙叉升降机管理", method = "平台下降", businessType = BusinessType.UPDATE)
    @GetMapping("/platformDrop")
    @ResponseBody
    @ApiOperation("平台下降")
    public ResponseData platformDrop(@RequestParam Integer plcDeviceId) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 平台下降");
        ToothHoistOper toothHoistOper = this.getTHODevice(plcDeviceId);
        if (!toothHoistOper.isControl()) {
            return ResponseData.error("设备未就绪");
        }
        if (toothHoistOper.isDropInPlace()) {
            return ResponseData.error("平台已在下降位置");
        }
        plcdevicedbService.platformDrop(this.getTHODevice(plcDeviceId));

        return ResponseData.success("平台下降成功", null);
    }

    @PreAuthorize("@ss.hasPermi('toothHoistOper:platformToothForwardIn')")
    @Log(title = "牙叉升降机管理", method = "正转入库", businessType = BusinessType.UPDATE)
    @GetMapping("/platformToothForwardIn")
    @ResponseBody
    @ApiOperation("正转入库")
    public ResponseData platformForwardIn(@RequestParam Integer plcDeviceId) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 正转入库");
        ToothHoistOper toothHoistOper = this.getTHODevice(plcDeviceId);
        if (!toothHoistOper.isControl()) {
            return ResponseData.error("设备未就绪");
        }
        if (!toothHoistOper.isRiseInPlace() && !toothHoistOper.isDropInPlace()) {
            return ResponseData.error("平台未到位");
        }
        if (toothHoistOper.isInPlaceSignal1() || toothHoistOper.isInPlaceSignal2()) {
            return ResponseData.error("入库目标位置有货，到位信号1或者2有信号");
        }
        plcdevicedbService.platformToothForwardIn(this.getTHODevice(plcDeviceId));

        return ResponseData.success("正转入库成功", null);
    }

    @PreAuthorize("@ss.hasPermi('toothHoistOper:platformToothForwardOut')")
    @Log(title = "牙叉升降机管理", method = "正转出库", businessType = BusinessType.UPDATE)
    @GetMapping("/platformToothForwardOut")
    @ResponseBody
    @ApiOperation("正转出库")
    public ResponseData platformForwardOut(@RequestParam Integer plcDeviceId) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 正转出库");
        ToothHoistOper toothHoistOper = this.getTHODevice(plcDeviceId);
        if (!toothHoistOper.isControl()) {
            return ResponseData.error("设备未就绪");
        }
        if (!toothHoistOper.isRiseInPlace() && !toothHoistOper.isDropInPlace()) {
            return ResponseData.error("平台未到位");
        }
        if (!toothHoistOper.isInPlaceSignal1() || !toothHoistOper.isInPlaceSignal2()) {
            return ResponseData.error("入库目标位置有货，到位信号1或者2有信号");
        }
        plcdevicedbService.platformToothForwardOut(this.getTHODevice(plcDeviceId));

        return ResponseData.success("设置正转出库成功", null);
    }

    @PreAuthorize("@ss.hasPermi('toothHoistOper:platformToothReverseIn')")
    @Log(title = "牙叉升降机管理", method = "反转入库", businessType = BusinessType.UPDATE)
    @GetMapping("/platformToothReverseIn")
    @ResponseBody
    @ApiOperation("反转入库")
    public ResponseData platformAutoReverseIn(@RequestParam Integer plcDeviceId) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 反转入库");
        ToothHoistOper toothHoistOper = this.getTHODevice(plcDeviceId);
        if (!toothHoistOper.isControl()) {
            return ResponseData.error("设备未就绪");
        }
        if (!toothHoistOper.isRiseInPlace() && !toothHoistOper.isDropInPlace()) {
            return ResponseData.error("平台未到位");
        }
        if (toothHoistOper.isInPlaceSignal1() || toothHoistOper.isInPlaceSignal2()) {
            return ResponseData.error("入库目标位置有货，到位信号1或者2有信号");
        }
        plcdevicedbService.platformToothReverseIn(this.getTHODevice(plcDeviceId));

        return ResponseData.success("设置反转入库成功", null);
    }

    @PreAuthorize("@ss.hasPermi('toothHoistOper:platformToothReverseOut')")
    @Log(title = "牙叉升降机管理", method = "反转出库", businessType = BusinessType.UPDATE)
    @GetMapping("/platformToothReverseOut")
    @ResponseBody
    @ApiOperation("反转出库")
    public ResponseData platformAutoReverseOut(@RequestParam Integer plcDeviceId) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 反转出库");
        ToothHoistOper toothHoistOper = this.getTHODevice(plcDeviceId);
        if (!toothHoistOper.isControl()) {
            return ResponseData.error("设备未就绪");
        }
        if (!toothHoistOper.isRiseInPlace() && !toothHoistOper.isDropInPlace()) {
            return ResponseData.error("平台未到位");
        }
        if (!toothHoistOper.isInPlaceSignal1() || !toothHoistOper.isInPlaceSignal2()) {
            return ResponseData.error("入库目标位置有货，到位信号1或者2有信号");
        }
        plcdevicedbService.platformToothReverseOut(this.getTHODevice(plcDeviceId));

        return ResponseData.success("设置反转出库成功", null);
    }

    @PreAuthorize("@ss.hasPermi('toothHoistOper:clearError')")
    @Log(title = "牙叉升降机管理", method = "牙叉升降机故障清除", businessType = BusinessType.UPDATE)
    @GetMapping("/clearToothError")
    @ResponseBody
    @ApiOperation("牙叉升降机故障清除")
    public ResponseData clearToothError(@RequestParam Integer plcDeviceId) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 号牙叉升降机故障清除信号");

        plcdevicedbService.toothHoistClearError(this.getTHODevice(plcDeviceId));

        return ResponseData.success("牙叉升降机故障清除成功", null);
    }

    /*************************************** 自动门 ****************************/
    /**
     * 读取自动门信息
     *
     * @param deviceName
     * @return
     */
    @PreAuthorize("@ss.hasPermi('plcDeviceDB:control')")
    @PostMapping("/plcAutoDoorDevice")
    @ApiOperation("手动控制自动门")
    @ResponseBody
    public ResponseData plcAutoDoorDevice(@RequestBody String deviceName) {
        HandleAutoDoor ht = plcdevicedbService.plcAutoDoorDevice(deviceName);
        if (ht == null) {
            return ResponseData.error("系统中无名称为" + deviceName + "的设备，请确认后重试");
        }
        return ResponseData.success(ht);
    }

    /**
     * 单体控制自动门
     *
     * @param result
     * @return
     */
    @PreAuthorize("@ss.hasPermi('plcDeviceManualOperation:plcAutoDoorDeviceW')")
    @Log(title = "plc设备手动操作", method = "单体控制自动门", businessType = BusinessType.UPDATE)
    @ApiOperation("单体控制自动门")
    @PostMapping("/plcAutoDoorDeviceW")
    @ResponseBody
    public ResponseData automaticDoor(@RequestBody WriteResult result) {
        String deviceName = result.getDeviceName();
        Integer open = result.getResult();
        AutomaticDoorOper automaticDoorOper = (AutomaticDoorOper) Plc.deviceBaseNameMap.get(deviceName);
        int doorNo = automaticDoorOper.getDeviceNo();
        if (StringUtils.isEmpty(deviceName) || automaticDoorOper == null) {
            return ResponseData.error("系统中无名称为" + deviceName + "的设备，请确认后重试");
        }
        PlcOper plcOper = PlcOperImpl.getPlcOper(automaticDoorOper.getPlc());
        switch (open) {
            case 0:
                try {
                    plcOper.automaticDoor(doorNo, true);
                } catch (IOException e) {
                    return ResponseData.error("通讯异常,开启自动门失败!");
                }
                return ResponseData.success("开启自动门 成功!");
            case 1:
                try {
                    plcOper.automaticDoor(doorNo, false);
                } catch (IOException e) {
                    return ResponseData.error("通讯异常,关闭自动门 失败!");
                }
                return ResponseData.success("关闭自动门 成功!");
            default:
                return ResponseData.error("不合法的参数!");
        }
    }

    @PreAuthorize("@ss.hasPermi('plcDeviceManualOperation:plcTransplanterDeviceW')")
    @Log(title = "plc设备手动操作", method = "移栽机任务完成编号清理", businessType = BusinessType.UPDATE)
    @ApiOperation("移栽机任务完成编号清理")
    @PostMapping("/plcTransplanterDeviceW")
    @ResponseBody
    public ResponseData plcTransplanterDeviceW(@RequestBody String deviceName) {
        TransplanterOper transplanterOper = (TransplanterOper) Plc.deviceBaseNameMap.get(deviceName);
        if (StringUtils.isEmpty(deviceName) || transplanterOper == null) {
            return ResponseData.error("系统中无名称为" + deviceName + "的设备，请确认后重试");
        }
        PlcOper plcOper = PlcOperImpl.getPlcOper(transplanterOper.getPlc());

        try {
            plcOper.readComplete(transplanterOper.getDeviceNo(), true);
        } catch (IOException e) {
            return ResponseData.error("网络异常!任务编号清理失败!");
        }
        return ResponseData.success("任务完成编号清理完成");
    }

    /******************************************扫码**********************************/

    /**
     * 读取条码
     *
     * @param deviceName
     * @return
     */
    @PreAuthorize("@ss.hasPermi('plcDeviceDB:control')")
    @ApiOperation("读取条码")
    @PostMapping("/readBarCode")
    @ResponseBody
    public ResponseData readBarCode(@RequestBody String deviceName) {
        ScannerHandleBean scannerHandleBean = plcdevicedbService.readBarCode(deviceName);
        if (scannerHandleBean == null) {
            return ResponseData.error("系统中无此设备，请确认后重试");
        }
        return ResponseData.success(scannerHandleBean);
    }

    /**
     * 写入读取结果
     *
     * @param result
     * @return
     */
    @PreAuthorize("@ss.hasPermi('plcDeviceManualOperation:writeResult')")
    @Log(title = "plc设备手动操作", method = "写入读取结果", businessType = BusinessType.UPDATE)
    @ApiOperation("写入读取结果")
    @PostMapping("/writeResult")
    @ResponseBody
    public ResponseData writeResult(@RequestBody WriteResult result) {
        String deviceName = result.getDeviceName();
        Integer sweResult = result.getResult();
        SweepCodeEquipmentOper sweepCodeEquipmentOper = (SweepCodeEquipmentOper) Plc.deviceBaseNameMap.get(deviceName);
        if (StringUtils.isEmpty(deviceName) || sweepCodeEquipmentOper == null) {
            return ResponseData.error("系统中无名称为" + deviceName + "的设备，请确认后重试");
        }
        PlcOper plcOper = PlcOperImpl.getPlcOper(sweepCodeEquipmentOper.getPlc());
        if (sweepCodeEquipmentOper.getPlc().systemBaseName.getDeviceNum() != 0) {
            return ResponseData.error("设备编号未清空，无法继续发送!");
        }
        switch (sweResult) {
            case 0:
                try {
                    plcOper.dataEligible(sweepCodeEquipmentOper.getDeviceNo(), true);
                } catch (IOException e) {
                    return ResponseData.error("通讯异常,设置扫码合格失败!");
                }
                return ResponseData.success("设置扫码合格成功!");
            case 1:
                try {
                    plcOper.dataEligible(sweepCodeEquipmentOper.getDeviceNo(), false);
                } catch (IOException e) {
                    return ResponseData.error("通讯异常,设置扫码不合格失败!");
                }
                return ResponseData.success("设置扫码不合格成功!");
            default:
                return ResponseData.error("不合法的参数!");
        }
    }

    /**
     * 扫码读取完成
     *
     * @param deviceName
     * @return
     */
    @PreAuthorize("@ss.hasPermi('plcDeviceManualOperation:writeReadFinal')")
    @Log(title = "plc设备手动操作", method = "写入读取完成", businessType = BusinessType.UPDATE)
    @ApiOperation("写入读取完成")
    @PostMapping("/writeReadFinal")
    @ResponseBody
    public ResponseData writeReadFinal(@RequestBody String deviceName) {
        SweepCodeEquipmentOper bcso = (SweepCodeEquipmentOper) Plc.deviceBaseNameMap.get(deviceName);
        if (deviceName.isEmpty() || bcso == null) {
            return ResponseData.error("系统中无名称为" + deviceName + "的设备，请确认后重试");
        }
        PlcOper plcOper = PlcOperImpl.getPlcOper(bcso.getPlc());
        if (bcso.getPlc().systemBaseName.getDeviceNum() != 0) {
            return ResponseData.error("设备编号未清空，无法继续发送!");
        }
        try {
            plcOper.readComplete(bcso.getDeviceNo(), true);
        } catch (IOException e) {
            return ResponseData.error("读取完成失败！");
        }
        return ResponseData.success("写入读取完成");
    }

    @ApiOperation("根据车辆编号获取车辆")
    @GetMapping("/getRgvByRgvNo")
    @ResponseBody
    public ResponseData getRgvByRgvNo(String rgvNo) {
        Rgv rgv = SystemInit.getByRgvNo(Integer.parseInt(rgvNo));
        return ResponseData.success(JSON.toJSONString(rgv), "操作成功");
    }
    /***************************************  单体输送线  ****************************/
    /**
     * 读取单体输送线信息
     *
     * @param deviceId
     * @return
     */
    @PreAuthorize("@ss.hasPermi('plcDeviceDB:control')")
    @PostMapping("/plcMonomerConveyorDevice")
    @ApiOperation("单体输送线")
    @ResponseBody
    public ResponseData plcMonomerConveyorDevice(@RequestBody Integer deviceId) {
        PlcDeviceDB plcDeviceDB = plcdevicedbService.getPlcDevById(deviceId);
        HandleMonomerConveyorOper hmco = SystemInit.plcMonomerConveyorDevice(deviceId);
        if (hmco == null) {
            return ResponseData.error("系统中无名称为" + plcDeviceDB.getDeviceName() + "的设备,请确认后重试");
        }
        return ResponseData.success(hmco);
    }

    /**
     * @param plcDeviceId
     * @return
     * @Description: 根据plcDeviceId获取单体输送线
     */
    public MonomerConveyorOper getMCODevice(Integer plcDeviceId) {
        return (MonomerConveyorOper) Plc.deviceMonomerConveyorCoordMap.get(Node.parseGrid(plcDeviceDBServiceImpl.getById(plcDeviceId).getDeviceLocation()));
    }

    @PreAuthorize("@ss.hasPermi('monomerConveyor:initMonomerConveyor')")
    @Log(title = "单体输送线管理", method = "设置单体输送线类型", businessType = BusinessType.UPDATE)
    @GetMapping("/initMonomerConveyor")
    @ResponseBody
    @ApiOperation("设置单体输送线类型")
    public ResponseData initMonomerConveyor(@RequestParam Integer plcDeviceId) throws IOException {
        log.info("接收到 设置 " + plcDeviceId + " 单体输送线类型");
        plcDeviceDBServiceImpl.setDeviceType(this.getMCODevice(plcDeviceId));
        return ResponseData.success("设置单体输送线类型成功");
    }


    @PreAuthorize("@ss.hasPermi('monomerConveyor:openScannerError')")
    @Log(title = "单体输送线管理", method = "打开扫码故障灯", businessType = BusinessType.UPDATE)
    @GetMapping("/openScannerError")
    @ResponseBody
    @ApiOperation("打开扫码故障灯")
    public ResponseData openScannerError(@RequestParam Integer plcDeviceId) throws IOException {
        log.info("接收到" + plcDeviceId + " 单体输送线打开扫码故障灯");
        plcDeviceDBServiceImpl.openScannerError(this.getMCODevice(plcDeviceId));
        return ResponseData.success("设置单体输送线打开扫码故障灯成功");
    }

    @PreAuthorize("@ss.hasPermi('monomerConveyor:closeScannerError')")
    @Log(title = "单体输送线管理", method = "关闭扫码故障灯", businessType = BusinessType.UPDATE)
    @GetMapping("/closeScannerError")
    @ResponseBody
    @ApiOperation("关闭扫码故障灯")
    public ResponseData closeScannerError(@RequestParam Integer plcDeviceId) throws IOException {
        log.info("接收到" + plcDeviceId + " 单体输送线关闭扫码故障灯");
        plcDeviceDBServiceImpl.closeScannerError(this.getMCODevice(plcDeviceId));
        return ResponseData.success("设置单体输送线关闭扫码故障灯成功");
    }

    @PreAuthorize("@ss.hasPermi('monomerConveyor:openOverweight')")
    @Log(title = "单体输送线管理", method = "打开超重灯", businessType = BusinessType.UPDATE)
    @GetMapping("/openOverweight")
    @ResponseBody
    @ApiOperation("单体输送线打开超重灯")
    public ResponseData openOverweight(@RequestParam Integer plcDeviceId) throws IOException {
        log.info("接收到" + plcDeviceId + " 单体输送线打开超重灯");
        plcDeviceDBServiceImpl.openOverweight(this.getMCODevice(plcDeviceId));
        return ResponseData.success("设置单体输送线打开超重灯成功");
    }

    @PreAuthorize("@ss.hasPermi('monomerConveyor:closeOverweight')")
    @Log(title = "单体输送线管理", method = "单体输送线关闭超重灯", businessType = BusinessType.UPDATE)
    @GetMapping("/closeOverweight")
    @ResponseBody
    @ApiOperation("单体输送线关闭超重灯")
    public ResponseData closeOverweight(@RequestParam Integer plcDeviceId) throws IOException {
        log.info("接收到" + plcDeviceId + " 单体输送线关闭超重灯");
        plcDeviceDBServiceImpl.closeOverweight(this.getMCODevice(plcDeviceId));
        return ResponseData.success("设置单体输送线关闭超重灯成功");
    }

    @PreAuthorize("@ss.hasPermi('monomerConveyor:openAlarmlamp')")
    @Log(title = "单体输送线管理", method = "打开无任务报警灯", businessType = BusinessType.UPDATE)
    @GetMapping("/openAlarmlamp")
    @ResponseBody
    @ApiOperation("打开无任务报警灯")
    public ResponseData openAlarmlamp(@RequestParam Integer plcDeviceId) throws IOException {
        log.info("接收到" + plcDeviceId + " 单体输送线打开无任务报警灯");
        plcDeviceDBServiceImpl.openAlarmlamp(this.getMCODevice(plcDeviceId));
        return ResponseData.success("设置单体输送线打开无任务报警灯成功");
    }

    @PreAuthorize("@ss.hasPermi('monomerConveyor:closeAlarmlamp')")
    @Log(title = "单体输送线管理", method = "关闭无任务报警灯", businessType = BusinessType.UPDATE)
    @GetMapping("/closeAlarmlamp")
    @ResponseBody
    @ApiOperation("关闭无任务报警灯")
    public ResponseData closeAlarmlamp(@RequestParam Integer plcDeviceId) throws IOException {
        log.info("接收到" + plcDeviceId + " 单体输送线关闭无任务报警灯");
        plcDeviceDBServiceImpl.closeAlarmlamp(this.getMCODevice(plcDeviceId));
        return ResponseData.success("设置单体输送线关闭无任务报警灯成功");
    }

    @PreAuthorize("@ss.hasPermi('monomerConveyor:clearInTask')")
    @Log(title = "单体输送线管理", method = "单体输送线任务清除", businessType = BusinessType.UPDATE)
    @GetMapping("/clearInTask")
    @ResponseBody
    @ApiOperation("单体输送线任务清除")
    public ResponseData clearInTask(@RequestParam Integer plcDeviceId) throws IOException {
        log.info("接收到" + plcDeviceId + " 单体输送线任务清除");
        plcDeviceDBServiceImpl.clearInTask(this.getMCODevice(plcDeviceId));
        return ResponseData.success("设置单体输送线任务清除成功");
    }

    @PreAuthorize("@ss.hasPermi('monomerConveyor:setMonomerConveyorAutoSpeed')")
    @Log(title = "单体输送线管理", method = "输送线自动速度", businessType = BusinessType.UPDATE)
    @GetMapping("/setMonomerConveyorAutoSpeed")
    @ResponseBody
    @ApiOperation("输送线自动速度")
    public ResponseData setMonomerConveyorAutoSpeed(@RequestParam Integer plcDeviceId, @RequestParam Integer speed) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 输送线自动速度");
        if (speed == null) {
            return ResponseData.error("设置输送线自动速度不能为空");
        } else if (speed < 1 || speed > 3000) {
            return ResponseData.error("输送线自动速度值超出设置范围，设置范围在[1,3000]");
        }
        plcDeviceDBServiceImpl.monomerConveyorAutoSpeed(this.getMCODevice(plcDeviceId), speed);

        return ResponseData.success("设置输送线自动速度成功", speed);
    }

    @PreAuthorize("@ss.hasPermi('monomerConveyor:setMonomerConveyorAutoAcc')")
    @Log(title = "单体输送线管理", method = "输送线自动加速时间", businessType = BusinessType.UPDATE)
    @GetMapping("/setMonomerConveyorAutoAcc")
    @ResponseBody
    @ApiOperation("输送线自动加速时间")
    public ResponseData setMonomerConveyorAutoAcc(@RequestParam Integer plcDeviceId, @RequestParam Integer time) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 输送线自动加速时间");
        if (time == null) {
            return ResponseData.error("设置输送线自动加速时间不能为空");
        } else if (time < 1 || time > 5000) {
            return ResponseData.error("输送线自动加速时间超出设置范围，设置范围在[1,5000]");
        }
        plcDeviceDBServiceImpl.monomerConveyorAutoAcc(this.getMCODevice(plcDeviceId), time);

        return ResponseData.success("设置输送线自动加速时间成功", time);
    }

    @PreAuthorize("@ss.hasPermi('monomerConveyor:setMonomerConveyorAutoDec')")
    @Log(title = "单体输送线管理", method = "输送线自动减速时间", businessType = BusinessType.UPDATE)
    @GetMapping("/setMonomerConveyorAutoDec")
    @ResponseBody
    @ApiOperation("输送线自动减速时间")
    public ResponseData setMonomerConveyorAutoDec(@RequestParam Integer plcDeviceId, @RequestParam Integer time) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 输送线自动减速时间");
        if (time == null) {
            return ResponseData.error("设置输送线自动减速时间不能为空");
        } else if (time < 1 || time > 5000) {
            return ResponseData.error("输送线自动减速时间超出设置范围，设置范围在[1,5000]");
        }
        plcDeviceDBServiceImpl.monomerConveyorAutoDec(this.getMCODevice(plcDeviceId), time);

        return ResponseData.success("设置输送线自动减速时间成功", time);
    }

    @PreAuthorize("@ss.hasPermi('monomerConveyor:setMonomerConveyorManualSpeed')")
    @Log(title = "单体输送线管理", method = "输送线手动速度", businessType = BusinessType.UPDATE)
    @GetMapping("/setMonomerConveyorManualSpeed")
    @ResponseBody
    @ApiOperation("输送线手动速度")
    public ResponseData setMonomerConveyorManualSpeed(@RequestParam Integer plcDeviceId, @RequestParam Integer speed) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 输送线手动速度");
        if (speed == null) {
            return ResponseData.error("设置输送线手动速度不能为空");
        } else if (speed < 1 || speed > 3000) {
            return ResponseData.error("输送线手动速度值超出设置范围，设置范围在[1,3000]");
        }
        plcDeviceDBServiceImpl.monomerConveyorManualSpeed(this.getMCODevice(plcDeviceId), speed);

        return ResponseData.success("设置输送线手动速度成功", speed);
    }

    @PreAuthorize("@ss.hasPermi('monomerConveyor:setMonomerConveyorManualAcc')")
    @Log(title = "单体输送线管理", method = "输送线手动加速时间", businessType = BusinessType.UPDATE)
    @GetMapping("/setMonomerConveyorManualAcc")
    @ResponseBody
    @ApiOperation("输送线手动加速时间")
    public ResponseData setMonomerConveyorManualAcc(@RequestParam Integer plcDeviceId, @RequestParam Integer time) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 输送线手动加速时间");
        if (time == null) {
            return ResponseData.error("设置输送线手动加速时间不能为空");
        } else if (time < 1 || time > 5000) {
            return ResponseData.error("输送线手动加速时间超出设置范围，设置范围在[1,5000]");
        }
        plcDeviceDBServiceImpl.monomerConveyorManualAcc(this.getMCODevice(plcDeviceId), time);

        return ResponseData.success("设置输送线手动加速时间成功", time);
    }

    @PreAuthorize("@ss.hasPermi('monomerConveyor:setMonomerConveyorManualDec')")
    @Log(title = "单体输送线管理", method = "输送线手动减速时间", businessType = BusinessType.UPDATE)
    @GetMapping("/setMonomerConveyorManualDec")
    @ResponseBody
    @ApiOperation("输送线手动减速时间")
    public ResponseData setMonomerConveyorManualDec(@RequestParam Integer plcDeviceId, @RequestParam Integer time) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 输送线手动减速时间");
        if (time == null) {
            return ResponseData.error("设置输送线手动减速时间不能为空");
        } else if (time < 1 || time > 5000) {
            return ResponseData.error("输送线手动减速时间超出设置范围，设置范围在[1,3000]");
        }
        plcDeviceDBServiceImpl.monomerConveyorManualDec(this.getMCODevice(plcDeviceId), time);

        return ResponseData.success("设置输送线手动减速时间成功", time);
    }

    @PreAuthorize("@ss.hasPermi('monomerConveyor:platformMonomerRiseMovement')")
    @Log(title = "单体输送线管理", method = "平台升位移量", businessType = BusinessType.UPDATE)
    @GetMapping("/platformMonomerRiseMovement")
    @ResponseBody
    @ApiOperation("平台升位移量")
    public ResponseData platformMonomerRiseMovement(@RequestParam Integer plcDeviceId) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 平台升位移量");

        plcDeviceDBServiceImpl.monomerConveyorRiseMovement(this.getMCODevice(plcDeviceId));

        return ResponseData.success("设置平台升位移量成功", null);
    }

    @PreAuthorize("@ss.hasPermi('monomerConveyor:platformMonomerDropMovement')")
    @Log(title = "单体输送线管理", method = "平台降位移量", businessType = BusinessType.UPDATE)
    @GetMapping("/platformMonomerDropMovement")
    @ResponseBody
    @ApiOperation("平台降位移量")
    public ResponseData platformMonomerDropMovement(@RequestParam Integer plcDeviceId) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 平台降位移量");

        plcDeviceDBServiceImpl.monomerConveyorDropMovement(this.getMCODevice(plcDeviceId));

        return ResponseData.success("设置平台降位移量成功", null);
    }

    @PreAuthorize("@ss.hasPermi('monomerConveyor:conveyorForwardIn')")
    @Log(title = "单体输送线管理", method = "输送线正转入库", businessType = BusinessType.UPDATE)
    @GetMapping("/conveyorForwardIn")
    @ResponseBody
    @ApiOperation("输送线正转入库")
    public ResponseData conveyorForwardIn(@RequestParam Integer plcDeviceId) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 输送线正转");
        MonomerConveyorOper monomerConveyorOper = this.getMCODevice(plcDeviceId);
        if (!monomerConveyorOper.isControl()) {
            return ResponseData.error("设备未就绪");
        }
        if (monomerConveyorOper.hasCargo()) {
            return ResponseData.error("单体输送线有出入库信号");
        }
        plcDeviceDBServiceImpl.conveyorForwardIn(this.getMCODevice(plcDeviceId));

        return ResponseData.success("输送线正转成功", null);
    }

    @PreAuthorize("@ss.hasPermi('monomerConveyor:conveyorReverseIn')")
    @Log(title = "单体输送线管理", method = "输送线反转入库", businessType = BusinessType.UPDATE)
    @GetMapping("/conveyorReverseIn")
    @ResponseBody
    @ApiOperation("输送线反转入库")
    public ResponseData conveyorReverseIn(@RequestParam Integer plcDeviceId) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 输送线反转");
        MonomerConveyorOper monomerConveyorOper = this.getMCODevice(plcDeviceId);
        if (!monomerConveyorOper.isControl()) {
            return ResponseData.error("设备未就绪");
        }
        if (monomerConveyorOper.hasCargo()) {
            return ResponseData.error("单体输送线有出入库信号");
        }
        plcDeviceDBServiceImpl.conveyorReverseIn(this.getMCODevice(plcDeviceId));

        return ResponseData.success("输送线反转成功", null);
    }

    @PreAuthorize("@ss.hasPermi('monomerConveyor:conveyorForwardOut')")
    @Log(title = "单体输送线管理", method = "输送线正转出库", businessType = BusinessType.UPDATE)
    @GetMapping("/conveyorForwardOut")
    @ResponseBody
    @ApiOperation("输送线正转出库")
    public ResponseData conveyorForwardOut(@RequestParam Integer plcDeviceId) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 输送线正转");
        MonomerConveyorOper monomerConveyorOper = this.getMCODevice(plcDeviceId);
        if (!monomerConveyorOper.isControl()) {
            return ResponseData.error("设备未就绪");
        }
        if (!monomerConveyorOper.hasCargo()) {
            return ResponseData.error("单体输送线没有出入库信号");
        }
        plcDeviceDBServiceImpl.conveyorForwardOut(this.getMCODevice(plcDeviceId));

        return ResponseData.success("输送线正转成功", null);
    }

    @PreAuthorize("@ss.hasPermi('monomerConveyor:conveyorReverseOut')")
    @Log(title = "单体输送线管理", method = "输送线反转出库", businessType = BusinessType.UPDATE)
    @GetMapping("/conveyorReverseOut")
    @ResponseBody
    @ApiOperation("输送线反转出库")
    public ResponseData conveyorReverseOut(@RequestParam Integer plcDeviceId) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 输送线反转");
        MonomerConveyorOper monomerConveyorOper = this.getMCODevice(plcDeviceId);
        if (!monomerConveyorOper.isControl()) {
            return ResponseData.error("设备未就绪");
        }
        if (!monomerConveyorOper.hasCargo()) {
            return ResponseData.error("单体输送线没有出入库信号");
        }
        plcDeviceDBServiceImpl.conveyorReverseOut(this.getMCODevice(plcDeviceId));

        return ResponseData.success("输送线反转成功", null);
    }

    @PreAuthorize("@ss.hasPermi('monomerConveyor:conveyorDoor1Forward')")
    @Log(title = "单体输送线管理", method = "自动门1正转", businessType = BusinessType.UPDATE)
    @GetMapping("/conveyorDoor1Forward")
    @ResponseBody
    @ApiOperation("自动门1正转")
    public ResponseData conveyorDoor1Forward(@RequestParam Integer plcDeviceId) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 自动门1正转");
        MonomerConveyorOper monomerConveyorOper = this.getMCODevice(plcDeviceId);
        if (!monomerConveyorOper.isControl()) {
            return ResponseData.error("设备未就绪");
        }
        plcDeviceDBServiceImpl.door1Forward(this.getMCODevice(plcDeviceId));

        return ResponseData.success("自动门1正转成功", null);
    }

    @PreAuthorize("@ss.hasPermi('monomerConveyor:conveyorDoor1Reverse')")
    @Log(title = "单体输送线管理", method = "自动门1反转", businessType = BusinessType.UPDATE)
    @GetMapping("/conveyorDoor1Reverse")
    @ResponseBody
    @ApiOperation("自动门1反转")
    public ResponseData conveyorDoor1Reverse(@RequestParam Integer plcDeviceId) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 自动门1反转");
        MonomerConveyorOper monomerConveyorOper = this.getMCODevice(plcDeviceId);
        if (!monomerConveyorOper.isControl()) {
            return ResponseData.error("设备未就绪");
        }
        plcDeviceDBServiceImpl.door1Reverse(this.getMCODevice(plcDeviceId));

        return ResponseData.success("自动门1反转成功", null);
    }

    @PreAuthorize("@ss.hasPermi('monomerConveyor:conveyorDoor3Forward')")
    @Log(title = "单体输送线管理", method = "自动门3正转", businessType = BusinessType.UPDATE)
    @GetMapping("/conveyorDoor3Forward")
    @ResponseBody
    @ApiOperation("自动门3正转")
    public ResponseData conveyorDoor3Forward(@RequestParam Integer plcDeviceId) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 自动门3正转");
        MonomerConveyorOper monomerConveyorOper = this.getMCODevice(plcDeviceId);
        if (!monomerConveyorOper.isControl()) {
            return ResponseData.error("设备未就绪");
        }
        plcDeviceDBServiceImpl.door3Forward(this.getMCODevice(plcDeviceId));

        return ResponseData.success("自动门3正转成功", null);
    }

    @PreAuthorize("@ss.hasPermi('monomerConveyor:conveyorDoor3Reverse')")
    @Log(title = "单体输送线管理", method = "自动门3反转", businessType = BusinessType.UPDATE)
    @GetMapping("/conveyorDoor3Reverse")
    @ResponseBody
    @ApiOperation("自动门3反转")
    public ResponseData conveyorDoor3Reverse(@RequestParam Integer plcDeviceId) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 自动门3反转");
        MonomerConveyorOper monomerConveyorOper = this.getMCODevice(plcDeviceId);
        if (!monomerConveyorOper.isControl()) {
            return ResponseData.error("设备未就绪");
        }
        plcDeviceDBServiceImpl.door3Reverse(this.getMCODevice(plcDeviceId));

        return ResponseData.success("设置自动门3反转成功", null);
    }

    @PreAuthorize("@ss.hasPermi('monomerConveyor:clearErrorMonomerConveyor')")
    @Log(title = "单体输送线管理", method = "单体输送线故障清除", businessType = BusinessType.UPDATE)
    @GetMapping("/clearErrorMonomerConveyor")
    @ResponseBody
    @ApiOperation("单体输送线故障清除")
    public ResponseData clearErrorMonomerConveyor(@RequestParam Integer plcDeviceId) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 号单体输送线故障清除信号");

        plcDeviceDBServiceImpl.monomerConveyorClearError(this.getMCODevice(plcDeviceId));

        return ResponseData.success("单体输送线故障清除成功", null);
    }

    @PreAuthorize("@ss.hasPermi('monomerConveyor:clearConveryTask')")
    @Log(title = "单体输送线管理", method = "输送线清除任务", businessType = BusinessType.UPDATE)
    @GetMapping("/clearConveryTask")
    @ResponseBody
    @ApiOperation("输送线清除任务")
    public ResponseData clearConveryTask(@RequestParam Integer plcDeviceId) {

        try {
            log.info("接收到 设置 " + plcDeviceId + " 号单体输送线清除任务");

            ((ShapeConveyorOper) Plc.deviceMonomerConveyorCoordMap.get(
                    Node.parseGrid(plcDeviceDBServiceImpl.getById(plcDeviceId).getDeviceLocation()))).clearTask();

            return ResponseData.success("输送线清除任务 成功", null);
        } catch (Exception e) {
            WcsUtil.exceptionLog(e, this.getClass());
            return ResponseData.error("输送线清除任务 失败");
        }
    }

    @PreAuthorize("@ss.hasPermi('shapeConveyor:setOpenShape')")
    @Log(title = "单体输送线管理", method = "设置外形检测启用", businessType = BusinessType.UPDATE)
    @GetMapping("/setOpenShape")
    @ResponseBody
    @ApiOperation("设置外形检测启用+外形检测类型")
    public ResponseData setOpenShape(@RequestParam Integer plcDeviceId, @RequestParam String currentDeviceType) throws IOException {
        log.info("接收到 设置 " + plcDeviceId + " 单体输送线+外形检测启用");
        plcDeviceDBServiceImpl.setOpenShape((ShapeConveyorOper) Plc.deviceShapeCoordMap.
                get(Node.parseGrid(plcDeviceDBServiceImpl.getById(plcDeviceId).getDeviceLocation())));
        return ResponseData.success("设置单体输送线+外形检测启用成功");
    }

    @PreAuthorize("@ss.hasPermi('shapeConveyor:setCloseShape')")
    @Log(title = "单体输送线管理", method = "设置外形检测关闭", businessType = BusinessType.UPDATE)
    @GetMapping("/setCloseShape")
    @ResponseBody
    @ApiOperation("设置外形检测启用+外形检测类型")
    public ResponseData setCloseShape(@RequestParam Integer plcDeviceId, @RequestParam String currentDeviceType) throws IOException {
        log.info("接收到 设置 " + plcDeviceId + " 单体输送线+外形检测关闭");
        plcDeviceDBServiceImpl.setCloseShape((ShapeConveyorOper) Plc.deviceShapeCoordMap.
                get(Node.parseGrid(plcDeviceDBServiceImpl.getById(plcDeviceId).getDeviceLocation())));
        return ResponseData.success("设置单体输送线+外形检测关闭成功");
    }

/**---------------------------单体拆叠盘机--------------------**/
@PreAuthorize("@ss.hasPermi('foldingOper:initFoldingMachine')")
@Log(title = "单体拆叠盘机管理", method = "设置单体拆叠盘机类型", businessType = BusinessType.UPDATE)
@GetMapping("/initFoldingMachine")
@ResponseBody
@ApiOperation("设置单体拆叠盘机类型")
public ResponseData initFoldingMachine(@RequestParam Integer plcDeviceId) throws IOException {
    try {
        log.info("接收到 设置 " + plcDeviceId + " 单体拆叠盘机类型");
        FoldingOper foldingOper = (FoldingOper) Plc.deviceFoldingOperCoordMap
                .get(Node.parseGrid(plcDeviceDBServiceImpl.getById(plcDeviceId).getDeviceLocation()));
        plcDeviceDBServiceImpl.setDeviceType(foldingOper);
        return ResponseData.success("设置单体拆叠盘机类型成功");
    } catch (Throwable e) {
        WcsFuncUtil.exceptionLog(e, this.getClass());
        return ResponseData.error("设置单体拆叠盘机类型失败");
    }
}
    /**
     * @param plcDeviceId
     * @return
     * @Description: 根据plcDeviceId获取牙叉升降机
     */
    public FoldingOper getFODevice(Integer plcDeviceId) {
        return (FoldingOper) Plc.deviceFoldingOperCoordMap.get(Node.parseGrid(plcDeviceDBServiceImpl.getById(plcDeviceId).getDeviceLocation()));
    }

    @PreAuthorize("@ss.hasPermi('foldingOper:setFoldingMachineAutoSpeed')")
    @Log(title = "单体拆叠盘机管理", method = "设置升降自动速度", businessType = BusinessType.UPDATE)
    @GetMapping("/setFoldingMachineAutoSpeed")
    @ResponseBody
    @ApiOperation("设置升降自动速度")
    public ResponseData setFoldingMachineAutoSpeed(@RequestParam Integer plcDeviceId, @RequestParam Integer speed) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 升降自动速度");
        if (speed == null) {
            return ResponseData.error("设置升降自动速度不能为空");
        } else if (speed < 1 || speed > 3000) {
            return ResponseData.error("升降自动速度值超出设置范围，设置范围在[1,3000]");
        }
        plcdevicedbService.foldingMachineAutoSpeed(this.getFODevice(plcDeviceId), speed);

        return ResponseData.success("设置升降自动速度成功", speed);
    }

    @PreAuthorize("@ss.hasPermi('foldingOper:setFoldingMachineAutoAcc')")
    @Log(title = "单体拆叠盘机管理", method = "设置升降自动加速时间", businessType = BusinessType.UPDATE)
    @GetMapping("/setFoldingMachineAutoAcc")
    @ResponseBody
    @ApiOperation("设置升降自动加速时间")
    public ResponseData setFoldingMachineAutoAcc(@RequestParam Integer plcDeviceId, @RequestParam Integer time) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 升降自动加速时间");
        if (time == null) {
            return ResponseData.error("设置升降自动加速时间不能为空");
        } else if (time < 1 || time > 5000) {
            return ResponseData.error("升降自动加速时间超出设置范围，设置范围在[1,5000]");
        }
        plcdevicedbService.foldingMachineAutoAcc(this.getFODevice(plcDeviceId), time);

        return ResponseData.success("设置升降自动加速时间成功", time);
    }

    @PreAuthorize("@ss.hasPermi('foldingOper:setFoldingMachineAutoDec')")
    @Log(title = "单体拆叠盘机管理", method = "设置升降自动减速时间", businessType = BusinessType.UPDATE)
    @GetMapping("/setFoldingMachineAutoDec")
    @ResponseBody
    @ApiOperation("设置升降自动减速时间")
    public ResponseData setFoldingMachineAutoDec(@RequestParam Integer plcDeviceId, @RequestParam Integer time) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 升降自动减速时间");
        if (time == null) {
            return ResponseData.error("设置升降自动减速时间不能为空");
        } else if (time < 1 || time > 5000) {
            return ResponseData.error("升降自动减速时间超出设置范围，设置范围在[1,5000]");
        }
        plcdevicedbService.foldingMachineAutoDec(this.getFODevice(plcDeviceId), time);

        return ResponseData.success("设置升降自动减速时间成功", time);
    }

    @PreAuthorize("@ss.hasPermi('foldingOper:setFoldingMachineManualSpeed')")
    @Log(title = "单体拆叠盘机管理", method = "设置升降手动速度", businessType = BusinessType.UPDATE)
    @GetMapping("/setFoldingMachineManualSpeed")
    @ResponseBody
    @ApiOperation("设置升降手动速度")
    public ResponseData setFoldingMachineManualSpeed(@RequestParam Integer plcDeviceId, @RequestParam Integer speed) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 升降手动速度");
        if (speed == null) {
            return ResponseData.error("设置升降手动速度不能为空");
        } else if (speed < 1 || speed > 3000) {
            return ResponseData.error("升降手动速度值超出设置范围，设置范围在[1,3000]");
        }
        plcdevicedbService.foldingMachineManualSpeed(this.getFODevice(plcDeviceId), speed);

        return ResponseData.success("设置升降手动速度成功", speed);
    }

    @PreAuthorize("@ss.hasPermi('foldingOper:setFoldingMachineManualAcc')")
    @Log(title = "单体拆叠盘机管理", method = "设置升降手动加速时间", businessType = BusinessType.UPDATE)
    @GetMapping("/setFoldingMachineManualAcc")
    @ResponseBody
    @ApiOperation("设置升降手动加速时间")
    public ResponseData setFoldingMachineManualAcc(@RequestParam Integer plcDeviceId, @RequestParam Integer time) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 升降手动加速时间");
        if (time == null) {
            return ResponseData.error("设置升降手动加速时间不能为空");
        } else if (time < 1 || time > 5000) {
            return ResponseData.error("升降手动加速时间超出设置范围，设置范围在[1,5000]");
        }
        plcdevicedbService.foldingMachineManualAcc(this.getFODevice(plcDeviceId), time);

        return ResponseData.success("设置升降手动加速时间成功", time);
    }

    @PreAuthorize("@ss.hasPermi('foldingOper:setFoldingMachineManualDec')")
    @Log(title = "单体拆叠盘机管理", method = "设置升降手动减速时间", businessType = BusinessType.UPDATE)
    @GetMapping("/setFoldingMachineManualDec")
    @ResponseBody
    @ApiOperation("设置升降手动减速时间")
    public ResponseData setFoldingMachineManualDec(@RequestParam Integer plcDeviceId, @RequestParam Integer time) throws IOException {

        log.info("接收到 设置 " + plcDeviceId + " 升降手动减速时间");
        if (time == null) {
            return ResponseData.error("设置升降手动减速时间不能为空");
        } else if (time < 1 || time > 5000) {
            return ResponseData.error("升降手动减速时间超出设置范围，设置范围在[1,5000]");
        }
        plcdevicedbService.foldingMachineManualDec(this.getFODevice(plcDeviceId), time);
        return ResponseData.success("设置升降手动减速时间成功", time);
    }
    @PreAuthorize("@ss.hasPermi('foldingOper:manualStop')")
    @Log(title = "单体拆叠盘机管理", method = "手动停止", businessType = BusinessType.UPDATE)
    @GetMapping("/manualStop")
    @ResponseBody
    @ApiOperation("手动停止")
    public ResponseData manualStop(@RequestParam Integer plcDeviceId) {
        try {
            log.info("接收到" + plcDeviceId + " 号拆叠盘机手动停止");
            FoldingManualAction.getInstance(this.getFODevice(plcDeviceId)).stopAction();
            return ResponseData.success("手动停止 成功", null);
        } catch (Exception e) {
            WcsUtil.exceptionLog(e, this.getClass());
            return ResponseData.error("手动停止 失败");
        }
    }
    @PreAuthorize("@ss.hasPermi('foldingOper:manualUp')")
    @Log(title = "单体拆叠盘机管理", method = "手动上升", businessType = BusinessType.UPDATE)
    @GetMapping("/manualUp")
    @ResponseBody
    @ApiOperation("手动上升")
    public ResponseData manualUp(@RequestParam Integer plcDeviceId) {
        try {
            log.info("接收到" + plcDeviceId + " 号拆叠盘机手动上升");
            FoldingManualAction.getInstance(this.getFODevice(plcDeviceId)).startAction(FoldingManualType.UP);
            return ResponseData.success("手动上升 成功", null);
        } catch (Exception e) {
            WcsUtil.exceptionLog(e, this.getClass());
            return ResponseData.error("手动上升 失败");
        }
    }
    @PreAuthorize("@ss.hasPermi('foldingOper:manualDown')")
    @Log(title = "单体拆叠盘机管理", method = "手动下降", businessType = BusinessType.UPDATE)
    @GetMapping("/manualDown")
    @ResponseBody
    @ApiOperation("手动下降")
    public ResponseData manualDown(@RequestParam Integer plcDeviceId) {
        try {
            log.info("接收到" + plcDeviceId + " 号拆叠盘机手动下降");
            FoldingManualAction.getInstance(this.getFODevice(plcDeviceId)).startAction(FoldingManualType.DOWN);
            return ResponseData.success("手动下降 成功", null);
        } catch (Exception e) {
            WcsUtil.exceptionLog(e, this.getClass());
            return ResponseData.error("手动下降 失败");
        }
    }
    @PreAuthorize("@ss.hasPermi('foldingOper:clearFoldingMachine')")
    @Log(title = "单体拆叠盘机管理", method = "清除任务", businessType = BusinessType.UPDATE)
    @GetMapping("/clearFoldingMachine")
    @ResponseBody
    @ApiOperation("清除任务")
    public ResponseData clearFoldingTask(@RequestParam Integer plcDeviceId) {
        try {
            log.info("接收到" + plcDeviceId + " 号拆叠盘机清除任务");
            this.getFODevice(plcDeviceId).clearTaskNo();
            return ResponseData.success("清除任务 成功", null);
        } catch (Exception e) {
            WcsUtil.exceptionLog(e, this.getClass());
            return ResponseData.error("清除任务 失败");
        }
    }

    @PreAuthorize("@ss.hasPermi('foldingOper:clearErrorTask')")
    @Log(title = "单体拆叠盘机管理", method = "清除故障", businessType = BusinessType.UPDATE)
    @GetMapping("/clearErrorTask")
    @ResponseBody
    @ApiOperation("清除故障")
    public ResponseData clearFoldingError(@RequestParam Integer plcDeviceId) {
        try {
            log.info("接收到" + plcDeviceId + " 号拆叠盘机清除故障");
            plcdevicedbService.setClearError(this.getFODevice(plcDeviceId));
            return ResponseData.success("清除故障 成功", null);
        } catch (Exception e) {
            WcsUtil.exceptionLog(e, this.getClass());
            return ResponseData.error("清除故障 失败");
        }
    }
    @PreAuthorize("@ss.hasPermi('foldingOper:reachInPlace')")
    @Log(title = "单体拆叠盘机管理", method = "推杆伸出", businessType = BusinessType.UPDATE)
    @GetMapping("/reachInPlace")
    @ResponseBody
    @ApiOperation("推杆伸出")
    public ResponseData reachInPlace(@RequestParam Integer plcDeviceId) {
        try {
            log.info("接收到" + plcDeviceId + " 号拆叠盘机推杆伸出");
            FoldingManualAction.getInstance(this.getFODevice(plcDeviceId)).startAction(FoldingManualType.PUSH);
            return ResponseData.success("推杆伸出 成功", null);
        } catch (Exception e) {
            WcsUtil.exceptionLog(e, this.getClass());
            return ResponseData.error("推杆伸出 失败");
        }
    }
    @PreAuthorize("@ss.hasPermi('foldingOper:shrinkInPlace')")
    @Log(title = "单体拆叠盘机管理", method = "推杆缩回", businessType = BusinessType.UPDATE)
    @GetMapping("/shrinkInPlace")
    @ResponseBody
    @ApiOperation("推杆缩回")
    public ResponseData shrinkInPlace(@RequestParam Integer plcDeviceId) {
        try {
            log.info("接收到" + plcDeviceId + " 号拆叠盘机推杆缩回");
            FoldingManualAction.getInstance(this.getFODevice(plcDeviceId)).startAction(FoldingManualType.RETRACT);
            return ResponseData.success("推杆缩回 成功", null);
        } catch (Exception e) {
            WcsUtil.exceptionLog(e, this.getClass());
            return ResponseData.error("推杆缩回 失败");
        }
    }
    @PreAuthorize("@ss.hasPermi('foldingOper:dismantlePallet')")
    @Log(title = "单体拆叠盘机管理", method = "拆单托", businessType = BusinessType.UPDATE)
    @GetMapping("/dismantlePallet")
    @ResponseBody
    @ApiOperation("拆单托")
    public ResponseData dismantlePallet(@RequestParam Integer plcDeviceId) {
        try {
            log.info("接收到" + plcDeviceId + " 号拆叠盘机拆单托");
            plcdevicedbService.foldingMachineDismantlePallet(this.getFODevice(plcDeviceId));
            return ResponseData.success("拆单托 成功", null);
        } catch (Exception e) {
            WcsUtil.exceptionLog(e, this.getClass());
            return ResponseData.error("拆单托 失败");
        }
    }
    @PreAuthorize("@ss.hasPermi('foldingOper:foldPallet')")
    @Log(title = "单体拆叠盘机管理", method = "叠单托", businessType = BusinessType.UPDATE)
    @GetMapping("/foldPallet")
    @ResponseBody
    @ApiOperation("叠单托")
    public ResponseData foldPallet(@RequestParam Integer plcDeviceId) {
        try {
            log.info("接收到" + plcDeviceId + " 号拆叠盘机叠单托");
            plcdevicedbService.foldingMachineFoldPallet(this.getFODevice(plcDeviceId));
            return ResponseData.success("叠单托 成功", null);
        } catch (Exception e) {
            WcsUtil.exceptionLog(e, this.getClass());
            return ResponseData.error("叠单托 失败");
        }
    }
    @PreAuthorize("@ss.hasPermi('foldingOper:dismantleAllPallet')")
    @Log(title = "单体拆叠盘机管理", method = "拆整托", businessType = BusinessType.UPDATE)
    @GetMapping("/dismantleAllPallet")
    @ResponseBody
    @ApiOperation("拆整托")
    public ResponseData dismantleAllPallet(@RequestParam Integer plcDeviceId) {
        try {
            log.info("接收到" + plcDeviceId + " 号拆叠盘机拆整托");
            plcdevicedbService.foldingMachineDismantleAllPallet(this.getFODevice(plcDeviceId));
            return ResponseData.success("拆整托 成功", null);
        } catch (Exception e) {
            WcsUtil.exceptionLog(e, this.getClass());
            return ResponseData.error("拆整托 失败");
        }
    }
    @PreAuthorize("@ss.hasPermi('foldingOper:foldAllPallet')")
    @Log(title = "单体拆叠盘机管理", method = "叠整托", businessType = BusinessType.UPDATE)
    @GetMapping("/foldAllPallet")
    @ResponseBody
    @ApiOperation("叠整托")
    public ResponseData foldAllPallet(@RequestParam Integer plcDeviceId) {
        try {
            log.info("接收到" + plcDeviceId + " 号拆叠盘机叠整托");
            plcdevicedbService.foldingMachineFoldAllPallet(this.getFODevice(plcDeviceId));
            return ResponseData.success("清除任务 成功", null);
        } catch (Exception e) {
            WcsUtil.exceptionLog(e, this.getClass());
            return ResponseData.error("叠整托 失败");
        }
    }
}
